-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
Problem
Currently, one can control separately whether autoscaling is applied to the x-axis and to the y-axis, but not whether it is only applied to the left or the right of the x-axis (or likewise to the bottom or the top of the y-axis). Yet this would be useful, e.g. in the case where the left limit is forced to zero whereas the right limit should follow autoscaling.
Concretely, I often have the following pattern:
ax = <create axes or fetch them from axes array>
ax.set(title="the title", xlabel="the label", xlim=(lo, hi), ...)
ax.plot(...)
yet if I want to force the left x-limit to 0 while leaving the right one autoscaled, I have to put the set_xlim() call after all the plotting, which splits axes configuration in two places. (One can also put the entire ax.set(...) call at the bottom, but this can be less clear especially when there are multiple axes being set up, as ax.set(title=...) also serves as self-commenting code to introduce what this axes will be about.)
Proposed solution
Make it possible to separately control whether the left and the right x-limits are autoscaled, and ideally make ax.set_xlim(0, None)
only turn off autoscaling on the left x-limit (via the relevant deprecation process).
Note that one question is how to compute the autoscaled right limit when the left limit is already forced. For simplicity, I believe this should behave as if the left limit wasn't forced, i.e. the right limit should be equal to the maximum value plus a margin equal to 0.05 (or whatever has been configured) times the entire x-span of the data; this way the behavior is as if ax.set_xlim(0, None)
had been called after the data is plotted. An alternative would be to not use the entire x-span, but only the span of data from x=0 to the maximum value (this would differ if some x-values are negative).