matplotlib学习之plot函数

来源:互联网 发布:smartmontools linux 编辑:程序博客网 时间:2024/06/02 05:13

plot函数可以绘画折线图等,参数:

linestyle:线条类型 
marker :折点(数据集中每个点) 
color :线条颜色 
linewidth :线条宽度 
label :该线条的标签,需要配合legend函数才能显示,

legend函数可以定义线条的标签(名字)放在图表的哪个地方,例如左上角等

import matplotlib.pyplot as pltsquares = [1,4,9,16,25]input_values=[1,2,3,4,5]plt.plot(input_values,squares,linestyle='--',marker='*',color='red',linewidth=2,label='lineA')plt.legend(loc='upper left')#设置图表标题,并给坐标轴加上标签plt.title("square Numbers",fontsize=24)plt.xlabel("Value",fontsize=14)plt.ylabel("square of Value",fontsize=14)#设置刻度标记的大小plt.tick_params(axis='both',labelsize=14)plt.show()


画出的图如下:



原创粉丝点击