xlim/ylim 和轴边界之间的区别

Difference Between xlim/ylim and Axis Boundaries

考虑使用 matplotlib 1.1.1 生成的以下图表:

ax.get_ylim = (30, 90)。当我运行下面的代码:

ax.plot_date(dates_to_plot, y_obs2)
foo = ax.get_ylim()
ax.fill_between(dates_to_plot, foo[0], y_obs2)

填充在 y_obs2(蓝色冻结线)和 30 之间——这是预期的。我想要的是在 y_obs2 和 20 之间填充(或者当时图表的下边界。)

如果我将 foo[0] 替换为普通的 0,水平线下方的区域将被完全填充,但这不是最佳选择,因为图表的下边界已更改为 0。此外,y_obs1(温度)可能变为负值(不幸的是!)。我一直无法找到一种方法来填充 y_obs2 线和图表下边界之间的区域——不管它是什么。

是否有一种我没有看到的方法可以提供图表 outside 边界的元组?

您想设置 ylimits auto=False 以确保在更改绘图数据时不会重新计算它们。

ax.plot_date(dates_to_plot, y_obs2)

# Get the current ylims
foo = ax.get_ylim()

# Prevent the axes ylims from changing automatically with new plots
ax.set_ylim(auto=False)

ax.fill_between(dates_to_plot, foo[0], y_obs2)

# You can always manually specify the ylims as well
# ax.set_ylim((lower, upper))