在Matplotlib中的x和基线x位置之间填充 [英] Fill between x and baseline x position in Matplotlib
问题描述
我正在寻找一种在matplotlib中使用fill_between在x1和x2之间进行着色的方法,而不是y1和y2.
I'm looking for a way to use fill_between in matplotlib to shade between x1 and x2 as opposed to y1 and y2.
我有一系列对数图,Y轴上的深度,x轴上的是测量变量,并且希望在绘制线的左侧或右侧(而不是上方或下方)着色.
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.
我相信这可以通过fill_between实现,但不能使其正常工作.
I'm sure this should be possible with fill_between but cant make it work.
例如:
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()
我已经附上了这样产生的图像: 本质上我想在图2的位置上绘制类似图1的图形
I have attached an image of what this produces: Essentially i want to plot something like plot 1 in the plot 2 position
谢谢您的建议
推荐答案
,您可以使用 fill_betweenx
you can use fill_betweenx
ax2.fill_betweenx(y,x, x2=0.5, where=x>0.5,interpolate=True)
这篇关于在Matplotlib中的x和基线x位置之间填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!