Python可视化matplotlib11-折线图:matplotlib.pyplot.plot

    技术2022-07-11  125

    折线图用来描述两个变量之间的关系,譬如方程y=ax+b中y随x变化而变化的关系;Matplotlib中绘制折线图的函数为plot() ,本文详细介绍该函数的相关参数;

    目录

    欢迎随缘关注@pythonic生物人

    折线图中常用参数

    详细参数 


    折线图中常用参数

    linestyle #线型linewidth #线宽marker #marker形状markersize #marker大小label #图例alpha #线和marker的透明度

    详细参数 

    官网资料:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html

    import math import matplotlib.pyplot as plt plt.figure(dpi=120) plt.plot(range(2,10),#x轴方向变量 [math.sin(i) for i in range(2,10)],#y轴方向变量 linestyle='--',#线型 linewidth=2,#线宽 color='red',#线和marker的颜色,当markeredgecolor markerfacecolor有设定时,仅仅控制line颜色 ##marker的特性设置 marker='^',#marker形状 markersize='15',#marker大小 markeredgecolor='green',#marker外框颜色 markeredgewidth=2, #marker外框宽度 markerfacecolor='red',#marker填充色 fillstyle='top',#marker填充形式,可选{'full', 'left', 'right', 'bottom', 'top', 'none'} markerfacecoloralt='blue',#marker未被填充部分颜色 markevery=2,#每隔一个画一个marker label='sin(x)',#图例 alpha=0.3,#线和marker的透明度 ) ##下面两条线使用默认参数绘制 plt.plot(range(2,10),[math.cos(i) for i in range(2,10)],label='cos(x)') plt.plot(range(2,10),[2*math.cos(i)+1 for i in range(2,10)],label='2*cos(x)+1') plt.legend()#绘制图例 plt.xlabel('x') plt.ylabel('f(x)')


    欢迎随缘关注@pythonic生物人 

     

    Processed: 0.011, SQL: 9