更多:Matplotlib…
同时需要了解Numpy和Matplotlib相关知识。
看代码吧,仔细了解清楚每句代码,每个函数。
# -*- coding:utf-8 -*- #! python3 import numpy as np import matplotlib.pyplot as plt # ========================================== # 圆的基本信息 # 1.圆半径 r = 2.0 # 2.圆心坐标 a, b = (0., 0.) # ========================================== # 方法一:参数方程 theta = np.arange(0, 2*np.pi, 0.01) x = a + r * np.cos(theta) y = b + r * np.sin(theta) fig = plt.figure() axes = fig.add_subplot(111) axes.plot(x, y) axes.axis('equal') plt.title('www.ai8py.com') # ========================================== # 方法二:标准方程 x = np.arange(a-r, a+r, 0.01) y = b + np.sqrt(r**2 - (x - a)**2) fig = plt.figure() #代表一个图形实例 axes = fig.add_subplot(111) #绘图网格 #plot()二维线画图函数,若y和x为同维向量,则以x为横坐标,y为纵坐标绘制连线图。 axes.plot(x, y) # 上半部 axes.plot(x, -y) # 下半部 plt.axis('equal')#轴对称 plt.title('www.ai8py.com')#窗口标题 # ========================================== plt.show()

20190614增加,用turtle更容易。
# !/usr/bin/env python3 # -*- coding: utf-8 -*- import turtle def main(): turtle.title('www.ai8py.com') turtle.circle(100) turtle.mainloop() if __name__ == '__main__': main()
