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
I was wondering whether there was interest in working on an "axis-swapping" API, which would allow an Axes to use its x axis as a y axis and vice-versa (or at least figuring out whether this would be possible). The idea would be to replace all the plotting functions that possess variants where the two axes are swapped (hist(..., orientation="horizontal"), fill_between/fill_betweenx, etc.) as well as those for which such a variant is being proposed (#5856).
So swap_axes() will just change the meaning of x and y args and some kwargs of future plots? After removing the obsolete parameter orientation, your example would end up like:
I'm not a big fan of the orientation state introduced with this concept. I have to know if swap_axes has been called earlier to know what my plot function will do.
It starts to get messy with additional parameters, e.g. align = {left, center, right} vs. align = {bottom, center, top}. Would need conditional checks on the allowed values and explanatory docstrings, that they depend on the orientation state.
an orientation parameter is probably easier to understand than swap_axes (e.g. does it swap existing plot elements or only the behavior of future plot commands?).
It's probably difficult to apply it to a complete consistent set of functions. Does it influence texts/annotations, hlines/vlines, added artists and patches?
On the first impression, this looks quite rabbit-holy.
IMO it would be a very nice utility to have. I would expect the latter behaviour, swapping/orientation to be essentially a property of the axes object, so that it would really only "happen" at draw time. Any other interaction with the axes (i.e. plotting) should be "unaware" of it.
The first case is really hard, the second case is almost impossible, both involving a bunch of state being carried around both by matplotlib and the user in their head, and all just to save the user a bit of cut and paste? I'm 👎 on this.
While the idea sounds fancy, it is "too clever". I do not think it's possible to implement this in a consistent way across the library. See my comment at #6569 (comment).
From an API perspective, I'm also not convinced that swapping axes (either for modifying future drawings ore for flipping the existing plot) is an intuitive way of working. People think of the figure a some sort of paper to draw on, and you'd rather say "draw horizontal bar plot" but not "rotate your paper and draw a bar plot".
I'm closing this as non feasible. If anybody wants to advocate this nevertheless, the way forward would be a working implementation for a number existing "rotated" plotting functions (barh(), fill_betweenx(), ...) to use it internally without already exposing this as public API. Such an implementation (if possible) would simplify these functions and be worth it, on its own. Whether it's something to add to the public API would need a separate discussion.
FWIW, this would be particularly useful when used with pandas, which has df.plot(), which (with the right type of data), plots lines (similar to plotting a array/list of lists). Transposing the data first is not possible, because the column headers are used for the line labels, and so that data is lost. Being able to flip the data and maintain those labels would be very useful. Though perhaps this is an issue for pandas...
Reacted by jakob-ra, Ken Mankoff, Ruben Braas, Hugo Ricateau, Amro Al-Baali, Julien Emile-Geay and helmut carter
Activity
tacaswell commentedon Jun 11, 2016
It is worth investigating.
Are you thinking a decorator-style thing
flip_xy(plot(x, y, ...))or an axes levelax.permute_axes(...)?anntzer commentedon Jun 11, 2016
I think it should happen at the axes level, in order to allow for swapped axes sharing.
sirimshin commentedon Mar 26, 2018
Do you have any examples of how it would work?
anntzer commentedon Mar 26, 2018
should be equivalent to
timhoffm commentedon Mar 27, 2018
So
swap_axes()will just change the meaning of x and y args and some kwargs of future plots? After removing the obsolete parameterorientation, your example would end up like:Just a few spontaneous thoughts:
swap_axeshas been called earlier to know what my plot function will do.align = {left, center, right}vs.align = {bottom, center, top}. Would need conditional checks on the allowed values and explanatory docstrings, that they depend on the orientation state.swap_axes(e.g. does it swap existing plot elements or only the behavior of future plot commands?).On the first impression, this looks quite rabbit-holy.
anntzer commentedon Mar 27, 2018
Oh, I definitely agree it'd be kind of a mess :-)
QuLogic commentedon Mar 27, 2018
Huh, I'd have thought you meant the opposite,
i.e., it swaps the Axis and all existing plotted things, but IIRC that's way way harder.
anntzer commentedon Mar 27, 2018
Well, that's a valid interpretation too... (but yes that looks even harder than my proposal)
andrzejnovak commentedon Sep 10, 2020
IMO it would be a very nice utility to have. I would expect the latter behaviour, swapping/orientation to be essentially a property of the axes object, so that it would really only "happen" at draw time. Any other interaction with the axes (i.e. plotting) should be "unaware" of it.
jklymak commentedon Sep 10, 2020
The first case is really hard, the second case is almost impossible, both involving a bunch of state being carried around both by matplotlib and the user in their head, and all just to save the user a bit of cut and paste? I'm 👎 on this.
timhoffm commentedon Sep 10, 2020
While the idea sounds fancy, it is "too clever". I do not think it's possible to implement this in a consistent way across the library. See my comment at #6569 (comment).
From an API perspective, I'm also not convinced that swapping axes (either for modifying future drawings ore for flipping the existing plot) is an intuitive way of working. People think of the figure a some sort of paper to draw on, and you'd rather say "draw horizontal bar plot" but not "rotate your paper and draw a bar plot".
I'm closing this as non feasible. If anybody wants to advocate this nevertheless, the way forward would be a working implementation for a number existing "rotated" plotting functions (
barh(),fill_betweenx(), ...) to use it internally without already exposing this as public API. Such an implementation (if possible) would simplify these functions and be worth it, on its own. Whether it's something to add to the public API would need a separate discussion.anntzer commentedon Sep 10, 2020
Let's close this as likely too hard; if someone really manages to come up with a reasonable implementation we can always revisit.
naught101 commentedon May 28, 2021
FWIW, this would be particularly useful when used with pandas, which has
df.plot(), which (with the right type of data), plots lines (similar to plotting a array/list of lists). Transposing the data first is not possible, because the column headers are used for the line labels, and so that data is lost. Being able to flip the data and maintain those labels would be very useful. Though perhaps this is an issue for pandas...