I'm looking for a way to use fill_between in matplotlib to shade between x1 and x2 as opposed to y1 and y2.
我在寻找一种方法,在matplotlib中使用fill_between在x1和x2之间建立阴影而不是在y1和y2之间。
I have a series of log plots, with depth on the Y axis, and the measured variable on the x axis and would like to shade to the left or right, as opposed to above or below, of the plotted line.
我有一系列的对数图,深度在Y轴上,测量变量在x轴上,想要在绘制线的左边或右边,而不是在上面或下面。
I'm sure this should be possible with fill_between but cant make it work.
我相信fill_between可以实现,但不能用。
As an example:
作为一个例子:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
gs = gridspec.GridSpec(3, 3)
ax1 = plt.subplot(gs[0, :])
ax2 = plt.subplot(gs[1:, 1])
y=np.random.uniform(0,1,30)
x=np.arange(30)
ax1.set_ylabel('Plot 1')
ax1.plot(x,y)
ax1.fill_between(x,y,0.5,where=y>0.5,interpolate=True)
ax2.set_ylabel('Plot 2')
ax2.plot(y,x)
ax2.set_ylim(30,0)
plt.show()
I have attached an image of what this produces: Essentially i want to plot something like plot 1 in the plot 2 position
我附加了一个图像来描述它所产生的东西本质上,我想要在图2的位置上绘制像图1这样的东西
Thankyou for any suggestions
谢谢有什么建议
1 个解决方案
#1
17
you can use fill_betweenx
您可以使用fill_betweenx
ax2.fill_betweenx(y,x, x2=0.5, where=x>0.5,interpolate=True)
#1
17
you can use fill_betweenx
您可以使用fill_betweenx
ax2.fill_betweenx(y,x, x2=0.5, where=x>0.5,interpolate=True)