Python中使用Matplotlib绘图示例详解(20)--自定义虚线图
- 自定义虚线图
import numpy as np import matplotlib.pyplot as plt x=np.linspace(0,10,500) y=np.sin(x) #设置数据 fig,ax=plt.subplots() #打开画板 line1,=ax.plot(x,y,label="Using set_dashes()") line1.set_dashes([15,10,10,2,25,10]) #set_dashes()设置是一对一对的,第一个是线的长度,第二个是空格的长度 #先绘制,再设置set_dashes(横杆模式<列表模式>) line2=ax.plot(x,y-0.2,dashes=[15,15],label="Using the dashes parameter") #在绘制的过程中进行dashes设置 ax.legend() plt.show()