You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: fill_between{x} does not respect Axes transform #25682
Using an axes transform with fill_between and fill_betweenx incorrectly sets the axes limits if the Axes coordinates are larger than the data coordinates.
Note that code is slightly modified from the example in the documentation, but with the y-data values and threshold reduced by a factor of 10. What you get a plot where the y-limits have been expanded as if I've plotted y-data spanning between (0,1), but get a fill that covers the entire axis space.
My guess is that the y-axis limits are being set by the y1/y2 values in data coordinates before the transform is applied to actually fill the regions. You will get the expected result as long as the provided Axes coordinate values are less than the extreme values of the y-data itself.
For example ax.fill_between(x, 0, 0.1, ...) gives a correct result.
But this issue means that you can't span the axes using this technique if your plotted data does not already span y=(0,1).
So the fundamental thing here is that transform is not actually directly inspected in fill_between's implementation (which is shared for x/y variants), instead that falls under the **kwargs that are passed straight to Polygon
But it does call self.update_datalim (in the linked line above)
I think when you are doing things in the (default) data axes, you do want to expand the lims.
But yes, when using axes limits (for either x or y) it should likely not.
One way to do that would be to manipulate the update[xy] parameters (they are passed explicitly despite being set to defaults and never passed in other similar calls). But not necessarily clear when to do so.
Alternatively it could be treated like axline, which I think would be my leaning at the moment:
Activity
ksunden commentedon Apr 14, 2023
matplotlib/lib/matplotlib/axes/_axes.py
Line 5413 in b86ebba
So the fundamental thing here is that
transformis not actually directly inspected infill_between's implementation (which is shared for x/y variants), instead that falls under the**kwargsthat are passed straight toPolygonBut it does call
self.update_datalim(in the linked line above)I think when you are doing things in the (default) data axes, you do want to expand the lims.
But yes, when using axes limits (for either x or y) it should likely not.
One way to do that would be to manipulate the
update[xy]parameters (they are passed explicitly despite being set to defaults and never passed in other similar calls). But not necessarily clear when to do so.Alternatively it could be treated like
axline, which I think would be my leaning at the moment:matplotlib/lib/matplotlib/axes/_axes.py
Lines 910 to 913 in b86ebba
Ref #17781, #17586
tacaswell commentedon Apr 14, 2023
That is probably the better option.
fixed issue matplotlib#25682
olinjohnson commentedon Apr 18, 2023
Hey, I'm looking to be a new contributor to the project. Like @ksunden suggested, it seems like amending
to
in
_fill_between_x_or_y()would work pretty well as a fix.I'm going to open a pull request - does this seem like a reasonable solution?
fixed issue matplotlib#25682