关键词:绘图库
官网: matplotlib.org
官网: matplotlib.org
安装:pip install matplotlib
一、一个散点图的绘制
#encoding=utf-8
import numpy as np
import matplotlib.pyplot as plt
def Main():
x = np.linspace(-np.pi,np.pi,256,endpoint=True)
c,s = np.cos(x),np.sin(x)
plt.figure(1)
plt.title("COS & SIN")
plt.scatter(x, c, color='red', marker='o', label='cos(x)')
plt.scatter(x, s, color='blue', marker='x', label='sin(x)')
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend(loc='upper left')
plt.grid()#网格线
#plt.axis([-1,1,-0.5,1])
#指定显示范围
plt.fill_between(x,np.abs(x)<0.5,c,c>0.5,color="green",alpha=0.25)
t=1
plt.plot([t,t],[0,np.cos(t)],"y",linewidth=3,linestyle="--")
plt.annotate("cos(1)",xy=(t,np.cos(t)),xycoords="data",xytext=(+10,+30),textcoords="offset points",
arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=.2"))
plt.show()
if __name__ == "__main__":
Main()