plt.plot(x,cos_y)# 保存图片 plt.savefig('正弦余弦曲线图.jpg')# 显示绘制的图片 plt.show() 运行效果如下: 上面的示例可以看到,调用两次plot函数,会将sin和cos曲线绘制到同一个二维坐标系中,如果想绘制到两张画布中,可以调用subplot()函数将画布分区。【示例】将画布分为区域,将图画到画布的指定区域 代码...
x, y1, y2, y3 = df["月份"],df["语文"],df["数学"], df["英语"] plt.figure(figsize=(5, 3)) # ls:line style 线样式 # marker:标记 # mfc:marker face color 背景颜色 # ms:marker size 标记点的大小 # alpha:透明度 plt.plot(x, y1, label="语文", c="g", ls="--", marker...
matplotlib.rcParams['font.family'] = ['Heiti TC'] # 绘图,设置(label)图例名字为'小龙虾价格',显示图例plt.legend() plt.plot(mouth,price,label='小龙虾价格',lw=5.0,ls="--",c='Red') # x轴标签 plt.xlabel('月份') # y轴标签 plt.ylabel('价格') # 图表标题 plt.title('小龙虾全年价格...
plot([1,2,3], [1,2,3], 'go-', label='line 1', linewidth=2)plot([1,2,3], [1,4,9], 'rs', label='line 2')axis([0, 4, 0, 10])legend() 使用一个绘画命令绘制多个线条,kwargs应用在所用线条中,例如: plot(x1, y1, x2, y2, antialiased=False) 所有线条都是锯齿状。 如果...
plot([1.8,2.8,3.8],[1,2,3],marker='2', markersize=15, color='#ec2d7a',label='常规marker') #非常规marker使用 #注意使用两个$符号包围名称 plt.plot([1,2,3],[4,5,6],marker='$\circledR$', markersize=15, color='r', alpha=0.5,label='非常规marker') plt.plot([1.5,2.5,3.5],[...
line, = ax.plot(t, s,color="green", lw=2) # 绘制一个红色,两端缩进的箭头 ax.annotate('local max', xy=(2.25, 1), xytext=(3, 1.5), xycoords='data', arrowprops=dict(facecolor='red', shrink=0.05) ) #y轴坐标范围 ax.set_ylim(-3, 3) ...
当在单个子图中有多条线、多组标记等时,它们尤其有用。当调用ax.legend()时,每个没有以下划线开头的标签且包含在轴对象中的艺术家都会生成一个轴图例条目。像ax.scatter()和ax.plot()这样的绘图函数将label作为参数,默认情况下,这是创建图例时使用的标签。
plot(x, y)#用默认线型、颜色绘制折线图plot(x, y,'bo')#用蓝色的圆点标识绘制点图plot(y)#绘制折线图,x坐标用[0,1,...,N-1]表示plot(y,'r+')#点图,x坐标同上,点样式为红色、+号 我们可以用Line2D的相关属性作为参数,在绘制时控制更多效果。Line属性和fmt可以混用,以下代码给出了相同样式的两种...
当在单个子图中有多条线、多组标记等时,它们尤其有用。当调用ax.legend()时,每个没有以下划线开头的标签且包含在轴对象中的艺术家都会生成一个轴图例条目。像ax.scatter()和ax.plot()这样的绘图函数将label作为参数,默认情况下,这是创建图例时使用的标签。
line, = ax.plot([1, 2, 3], label='Inline label') ax.legend() or:: line, = ax.plot([1, 2, 3]) line.set_label('Label via method') ax.legend() Specific lines can be excluded from the automatic legend element selection by defining a label starting with an underscore. ...