Python数据可视化学习笔记1-绘制折线图

    xiaoxiao2022-07-07  223

    import matplotlib.pyplot as plt input_values = [1,2,3,4,5] squares = [1,4,9,16,25] plt.plot(input_values,squares,linewidth = 5) plt.title('Square Numbers',fontsize =24) plt.xlabel('Value',fontsize =14) plt.ylabel('Square Value',fontsize =24) plt.tick_params(axis = 'both',labelsize = 14) plt.show() plt.plot(input_values,squares,linewidth = 5) 方法plt.plot()绘制图形。 参数linewidth:决定了plot()绘制的线条的粗细。plt.title('Square Numbers',fontsize =24) 函数title():给图表指定标题。 参数fontsize:指定了图表中文字的大小。plt.xlabel('Value',fontsize =14) plt.ylabel('Square Value',fontsize =24) 函数xlabel()和ylabel()为每条轴设置标题。plt.tick_params(axis = 'both',labelsize = 14) 函数tick_params设置刻度的样式,其中指定的实参将影响x和y轴上的刻度,并将刻度标记的字号设置为14。(labelsize=14)plt.show():打开查看器并显示图形。  

    程序运行结果:

    最新回复(0)