gpt4 book ai didi

python - matplotlib中2个y坐标之间的阴影区域

转载 作者:行者123 更新时间:2023-12-01 01:51:50 25 4
gpt4 key购买 nike

我正在尝试基于两个垂直坐标创建一个阴影矩形(矩形的长度应跨越整个 x 轴)。我尝试将 fill_ Between 与以下内容一起使用(p1 和 p2 是数据坐标):

f, ax1 = plt.subplots()   
x = np.linspace(200,300,2000)
y = x**(2)
y1 = x
p1 = 4700
p2 = 7700

ax1.plot(x, y, lw=2)
ax1.set_xlabel('Temperature $[K]$', fontweight='bold')
ax1.set_ylabel('Pressure $[mb]$', fontweight='bold')
ax1.fill_between(x, y1.fill(p1), y1.fill(p2))

但我收到以下错误:

TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

出了什么问题?有更好的方法吗?

谢谢!!

最佳答案

可能您想使用 axhspan .

p1 = 4700
p2 = 7700
ax1.axhspan(p1, p2, color="limegreen", alpha=0.5)

enter image description here

关于python - matplotlib中2个y坐标之间的阴影区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50646523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com