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...
x = np.linspace(0, 10, 1000) foriinrange(4): 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...
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) # 手动创建第二个图例,并将作者添加到图表中frommatplotlib.legend import Leg...
brown#F4A460s 下面是官网列出的一些命名的颜色: 标记(Markers): 线条类型(Line Styles):
The line style can be written in a shorter syntax:linestyle can be written as ls.dotted can be written as :.dashed can be written as --.Example Shorter syntax: plt.plot(ypoints, ls = ':') Result: Try it Yourself » Line Styles...
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') ...
star1、line plot【折线图】 官网教程:https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html 详细实战教程:Python可视化|matplotlib11-折线图plt.plot 快速教程: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 importnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotasplt ...
lines += ax.plot(x, np.sin(x - i * np.pi / 2), styles[i], color='k') ax.axis('equal') # 设置第一个图例要显示的线条和标签 ax.legend(lines[:2], ['line A', 'line B'], loc='upper right', frameon=False) # 创建第二个图例,通过add_artist方法添加到图上 ...