x=np.linspace(0,10,100)y=np.sin(x)plt.figure(figsize=(12,8))line_styles=['-','--',':','-.','']labels=['Solid','Dashed','Dotted','Dash-dot','None']fori,styleinenumerate(line_styles):plt.plot(x,y+i,linestyle=style,label=f'{labels[i]}- how2matplotlib.com')plt.title(...
importmatplotlib.pyplotasplt x=[1,2,3,4,5]y=[2,3,5,7,11]plt.plot(x,y,linestyle=':',label='dotted line')plt.legend()plt.show() Python Copy Output: 4. 点划线样式 点划线样式是点线和虚线的结合。 importmatplotlib.pyplotasplt x=[1,2,3,4,5]y=[2,3,5,7,11]plt.plot(x,y,li...
The line style can be written in a shorter syntax: linestylecan be written asls. dottedcan be written as:. dashedcan be written as--. Example Shorter syntax: plt.plot(ypoints, ls =':') Result: Try it Yourself » Line Styles
x = np.linspace(0,10,1000)foriinrange(len(styles)): lines += ax.plot(x, np.sin(x-i * np.pi/2), styles[i], color=colors[i]) ax.axis('equal')#设置第一个图例要显示的元素和标签ax.legend(lines[:2], ['LineA','LineB'], loc='upper right', frameon=False)#根据一个Legend对象...
lines += ax.plot(x, np.sin(x - i * np.pi / 2), styles[i], color='black') ax.axis('equal') # 设置第一个图例要显示的线条和标签 ax.legend(lines[:2], ['line A','line B'], loc='upper right', frameon=False,fontsize=15) ...
Markers and line styles 上面画的线都是一样的,其实我们可以画出各种不同的线 Marker就是指形成线的那些点 plot() supports an optional third argument that contains a format string for each pair of X, Y arguments in the form of: plt.plot(X, Y, '<format>', ...) ...
plt.plot(x, y) # 3、图形展示 plt.show() 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 效果图如下: 利用matplotlib绘制一周天气变化折线图 import matplotlib.pyplot as plt import numpy as np ...
lines = plt.plot(x, y) # 直线是 plt.Line2D 实例的列表 plt.legend(lines[:2], ['first', 'second']); 1. 2. 3. 4. 5. 我通常在实践中发现使用第一种方法更清晰,将标签应用于你想要在图例上显示的绘图元素: plt.plot(x, y[:, 0], label='first') ...
(0, 10, 1000) # 画四条线 for i in range(4): lines += ax.plot(x, np.sin(x - i * np.pi / 2), styles[i], color=colors[i]) ax.axis('equal') # 设置图例要显示的线条和标签 ax.legend(lines, ['line A', 'line B', 'line C', 'line D'], loc='upper right', frameon...
star1、line plot【折线图】 官网教程:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html 详细实战教程:Python可视化|matplotlib11-折线图plt.plot 快速教程: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 importnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotasplt ...