DaveL17 DaveL17 - 2 years ago 95
Python Question

Difference Between xlim/ylim and Axis Boundaries

Considering the following chart produced with matplotlib 1.1.1:

enter image description here

ax.get_ylim = (30, 90)
. When I run the following code:

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

the fill is between y_obs2 (the blue freeze line) and 30 -- which is expected. What I want is to fill between y_obs2 and 20 (or whatever the lower boundary is for the chart at that time.)

If I replace
with just plain
, the area below the horizontal line is completely filled, but that's not optimal because the chart's lower boundary is changed to 0. Further, y_obs1 (the temperature) may become negative (unfortunately!). I have been unable to find a method to fill the area between the y_obs2 line and the chart's lower boundary--whatever it might be.

Is there a method that I'm not seeing that can provide a tuple of the chart's outside boundaries?

Answer Source

You want to set the ylimits auto=False to ensure that they aren't re-calculated when you change the plotted data.

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.fill_between(dates_to_plot, foo[0], y_obs2)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download