参考资料:
3359 blog.csdn.net/QQ _ 44503987/article/details/97620193
https://www.runoob.com/w3cnote/matplotlib-tutorial.html
3359 zhidao.Baidu.com/question/579467333.html
3359 blog.csdn.net/weixin _ 36384501/article/details/112215755
pyplot图和axes图
3359 blog.csdn.net/dont la/article/details/98327176
1.np模块
线性空间函数、线性空间(x,y,n )可以在给定区间内生成等间隔的n个
2.matplotlib.pyplot模块
— plot函数
表达式pyplot.plot(x,y,format_string,**kwargs ) ) ) ) ) ) ) )。
表示x轴的数据
y表示y轴的数据
用于显示format_string曲线的字符串
**kwargs想要绘制多条曲线时,可以接着填写第二条曲线的x、y、format_string
— rcParams函数
使用rc配置文件定义绘图的各种缺省属性,称为rc配置文件或rc参数
参考: https://blog.csdn.net/QQ _ 30815237/article/details/87903024
figure(figsize(a,b ),dpi=c )可以设置图的大小
subplot(a,b,c )设置子图
xlim(a,b )设定x轴上下限
xticks(list ) )设置x轴标记
plt.gca ) )获取当前子图
plt.legend (函数,为图像添加图例
参数是一组元组对象,它是返回元组列表的zip (函数
— scatter函数
参考: https://blog.csdn.net/Qiu 931110/article/details/68130199 /
用于生成散点图
importnumpyasnpimportmatplotlib.pyplotasplt.figure (fig size=(8,5 ),dpi=80 ) PLT.subplot ) 1,1 ) PLT )。
— plt.annotate()函数
用于尺寸文字的函数、文字的内容、需要标记的点、尺寸文字的位置、箭头的格式等…
PLT.annotate (s=‘str’,xy=) x,y ),xytext=) L1,l2 ), )
见https://blog.csdn.net/QQ _ 36387683/article/details/101377416
代码
importnumpyasnpimportmatplotlib.pyplotaspltfrompylabimportmpl.RC (' font ',family='SimHei ' ), size=7) #配置字体mpl.rcparams [ ' axes.unicode _ MINUS ' ]=false #默认保存减号为框# mpl.rcparams [ ' lines.line ] linestyle='-. ') #设定线mpl.rcparams [ ' image.cmap ' ]=[ ' gray ' ] # cos曲线' ) #标题PLT.ylabel(y坐标) x=NP.lip ' go-',linewidth=2.5,linestyle='-',label='cosine ' ) #绿,坐标点为实线PLT.plot(x,s, ' rp-. ' )红色,坐标点为label='sine ' ) #红色,坐标点为实心五边形,点划线#优化边界xmin,xmax=X.min (,xmin ),ymax=C.min ),c xmax dx ) PLT.ylim ) ymin-dy,ymax latexPLT.xticks([-NP.pi,- NP.pi/2,0,NP.pi/2,np.pi],[ r ' $ $ 使用pi/2$ '的r'$1$'(#移动脊柱的ax=plt.gca ) ax.spines['right'].set_color )右、上两条脊柱为透明的ax.spines [ ' ] 0 ) #图例PLT.legend(loc='upperright ' ) t=2*NP.pi/3PLT.plot([t,t],[0,np.cos(t ) t],color='。 NP.sin(t )、xycoords='data )、xy text=(10,30 )、textcoords='offset points )、fontsize=16、arrow props=drops linewidth=2.5,linestyle='-- ' ) (pline cos(FRAC(2) pi ) )FRAC )1) )2) $,xy=(t,np.cos(t ) arrowprops=dict(arrowstyle='-',connectionstyle='arc3,rad=.2 ' ) )代码执行后,将得到下图