plt.plot(x, y1, label='sin(x)', color='r', linestyle='-') plt.plot(x, y2, label='cos(x)', color='g', linestyle='--') plt.plot(x, y3, label='tan(x)', color='b', linestyle=':') 添加标题和标签 plt.title('Multiple Lines
figure(figsize=(480/my_dpi, 480/my_dpi), dpi=my_dpi) # multiple line plot for column in df.drop('x', axis=1): plt.plot(df['x'], df[column], marker='', color='grey', linewidth=1, alpha=0.4) # Now re do the interesting curve, but biger with distinct color plt.plot(df[...
# 绘制第二条折线图,假设数据列名为'Column4',线条颜色为蓝色,线条样式为虚线,线条宽度为1 plt.plot(x_values, filtered_data['Column4'].values, color='blue', linestyle='dashed', linewidth=1) # 设置图形标题和坐标轴标签,这里假设标题为'Multiple Line Plot',x轴标签为'Time Series',y轴标签为'Data...
() # 绘制多线图 ax.plot(x, y1, label='sin(x)') ax.plot(x, y2, label='cos(x)') ax.plot(x, y3, label='tan(x)') # 添加图例 ax.legend() # 设置标题和坐标轴标签 ax.set_title('Multiple Line Plot') ax.set_xlabel('X-axis') ax.set_ylabel('Y-axis') # 显示图形 plt....
# 添加图例plt.legend()# 添加坐标轴标签plt.xlabel('X-axis')plt.ylabel('Y-axis')# 添加标题plt.title('Multiple Line Plots in Python') 以上就是如何在Python中使用Matplotlib库绘制多个线形的方法。通过灵活使用Matplotlib库的各种函数和参数,我们可以轻松绘制出各种复杂的图形。希望这篇文章能对您有所帮助...
(480/my_dpi, 480/my_dpi), dpi=my_dpi) # multiple line plot for column in df.drop('x', axis=1): plt.plot(df['x'], df[column], marker='', color='grey', linewidth=1, alpha=0.4) # Now re do the interesting curve, but biger with distinct color plt.plot(df['x'], df['...
importmatplotlib.pyplotaspltimportnumpyasnp# Example datax=np.linspace(0,10,100)y1=np.sin(x)y2=np.cos(x)y3=np.tan(x)y4=np.exp(-x)# Creating Multiple Subplots for Line Plotsfig,axes=plt.subplots(nrows=2,ncols=2,figsize=(10,8))# Line Plot 1axes[0,0].plot(x,y1,label='sin(...
plt.plot(x, y) # Plot another line on the same chart/graph plt.plot(x, z) plt.show() Python plot multiple lines on the same graph In the above example, the data is prepared as lists as x, y, z. Thenmatplot.pyplot.plot()function is called twice with different x, y parameters ...
plot(x, y, 'bo') # 使用蓝色圆圈标记绘制x和y plot(y) # 使用x作为索引数组0..N-1绘制y plot(y, 'r+') # 同上,但带有红色加号 1. 2. 3. 4. 您可以使用 Line2D 属性作为关键字参数,以便对外观进行更多控制。行属性和 fmt 可以混合使用。以下两个调用产生相同的结果: ...
plt.title('Multiple Curves on a Single Plot') plt.legend() 显示图像 plt.show() 在上述代码中,通过多次调用plt.plot函数绘制了三条曲线,并通过label参数为每条曲线添加了标签。最后,通过plt.legend函数显示图例。 2、使用循环绘制多条曲线 如果需要绘制多条曲线,可以使用循环来简化代码。