matplotlib 模块 画图 例1
1 #!/usr/bin/python 2 # -*- coding: UTF-8 -*- 3 4 import matplotlib.pyplot as plt 5 import numpy as np 6 #To draw y =x^2 (-3<=x<=3) 7 x=[x for x in range(100)] 8 y = [ele**2 for ele in x] 9 z = [ele *2 for ele in x] 10 # plt.plot(x,y,'ro-',label="y=x^2")#作图:y关于x的曲线 label是曲线标签 "ro-"表示红色然后加o 11 plt.plot(x,y,'ro-',label=r"$y=x^2$") 12 # plt.plot(x,z,'g-',label="y =2x")#作图:z关于x的曲线 g-表示绿色 13 plt.plot(x,z,'g-',label=r"$y =2*x$") 14 15 plt.xlabel('x') #横坐标的标题 16 plt.ylabel('y') #纵坐标的标题 17 plt.title('Paralabo and line') #图的标题 18 19 plt.plot(z,y,) 20 21 plt.legend() #显示符号,即x和y曲线的说明 22 plt.show() #显示