在matplotlib

时间:2015-10-12 13:57:34

标签: python matplotlib

我想在特定限制下绘制一条线或颜色区域

例如颜色或绘制线位于/大于10且小于/小于-10

喜欢这个例子

enter image description here enter image description here

为区域着色时,颜色应该是透明的

1 个答案:

答案 0 :(得分:1)

可以使用fill_betweenimport matplotlib.pyplot as plt import numpy as np #Define min and max line minline = -10 maxline = 10 #Generate dummy plotting data x = np.arange(0.0, 2, 0.01) y1 = 25*np.sin(2*np.pi*x)-10 y2 = 30*np.sin(4*np.pi*x)-10 maxy=max(y1.max(),y2.max()) miny=min(y1.min(),y2.min()) fig, axs = plt.subplots(2,1) #Plot dummy data for ax in axs: ax.plot(x,y1,'b') ax.plot(x,y2,'g') #Draw lines axs[0].axhline(y=minline,color='r') axs[0].axhline(y=maxline,color='r') #Draw filled regions axs[1].fill_between(x,minline,miny,color='r',alpha=0.3) axs[1].fill_between(x,maxline,maxy,color='r',alpha=0.3) plt.show() 函数

来完成此操作
table{
    width: 2200px;
}

给出,

enter image description here