Python 在 Matplotlib 中的 x 和基线 x 位置之间填充
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15589643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fill between x and baseline x position in Matplotlib
提问by user1665220
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

我附上了这产生的图像:本质上我想在 plot 2 位置绘制类似 plot 1 的东西

Thankyou for any suggestions
谢谢你的任何建议
采纳答案by Francesco Montesano
you can use fill_betweenx
您可以使用 fill_betweenx
ax2.fill_betweenx(y,x, x2=0.5, where=x>0.5,interpolate=True)

