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

标签 python matplotlib

我正在尝试基于两个垂直坐标创建一个阴影矩形(矩形的长度应跨越整个 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/

相关文章:

python - 尝试匹配多个参数化测试时,pytest -k 表达式失败

python - Mongoexport 导出无效的 json 文件

python - TinyCSS 和 GTK 主题 @define-color

python - Matplotlib 日期操作,使年刻度每 12 个月出现一次

python - mod_wsgi错误:ImportError:dlopen(/usr/local/lib/python3.6/site-packages/cv2.so,2):找不到符号:_iconv

Python,当动画由传入传感器数据馈送时退出 matplotlib FuncAmination()

python - 如何在 matplotlib 中绘制 3 列饼图?

python - 在 4×n 网格中绘制子图并共享 y 轴

python-2.7 - Python 条形图中 error_kw 的关键字值

python - 如何根据行值获取 Pandas 中的列名?