Repository navigation
Conversation
|
This seems reasonable to me. However, you will need to make the tests pass, and this is a breaking change (i.e. imagine someone has used the workaround, now their plot legend will be wrong) so we need to have some sort of deprecation path. |
|
okay, eventually figured out how to run the tests. is there any established transition/deprecation path in matplotlib? |
|
I think you'll have to do a song and dance with a kwarg that default to the old behavior but warns, and then defaults to the new behavior? Unless this is so obviously desirable that the old way was a bug, in which case we could maybe just have a kwarg to give the old behavior. |
f4f00bb to
39eb6fb
Compare
3ad759e to
ee809ff
Compare
|
I'm popping to draft as this needs to pass the tests. However, from the comment above, its not clear if this change is desired? |
ee809ff to
5737f72
Compare
|
Imo the feature is desired, I'm bodging around it in production. If other users will appreciate turning it on-by-default or if off-by-default is a better setting is unclear to me. |
|
okay, found the button to remove draft status. let me just point out atm the branch is such that the default is unchanged. |
This will does not alter the order in which stackplot elements are show on the axes, colors are used, labels are assigned, etc. It is only (meant to) change the order in which handles are stored in the axes object and thus in which legend entries appear by default. With this change the top most entry in the legend should be the top most plotted stack plot component.
2347803 to
a035ba3
Compare
tacaswell
left a comment
There was a problem hiding this comment.
We could 🚲 🏠 the bottom_area and not_bottom_areas internal function names a bit, but I do not think it is worth holding over that.
|
@pseyfert Looks good! I added / removed a bunch of labels, I think they are now correct (no API change, has docs, has a test, and is a new feature). |
timhoffm
left a comment
There was a problem hiding this comment.
The implementation is good.
I'm not quite happy with the name top_to_bottom. It's unclear what this means. My first intuition on that name was, that for data [y1, y2, y3] it will plot y1 above y2 above y3.
Maybe something like draw_top_first? Name suggestions welcome.
| above the other plot components in the legend. That is, for | ||
| ``stackplot(x, y1, y2, y3)``, the legend will contain y3 above y2 and | ||
| y2 above y1. | ||
| The default behaviour is plotting the bottom area first. |
There was a problem hiding this comment.
| The default behaviour is plotting the bottom area first. | |
| The default behaviour is plotting the bottom area first. | |
| .. versionadded:: 3.7 |
| .. code-block:: python | ||
|
|
||
| from matplotlib import pyplot as plt | ||
| plt.x = [1, 2, 3, 4, 5] |
There was a problem hiding this comment.
| plt.x = [1, 2, 3, 4, 5] | |
| x = [1, 2, 3, 4, 5] |
|
|
||
| The order of entries in a legend of a `~matplotlib.axes.Axes.stackplot` can be inverted with the option ``top_to_bottom``. In the below example, a viewer would see the area for ``y3`` above ``y2``, and ``y2`` above ``y1``. Here the legend will be generated in the same way such that ``y3`` appears above ``y2`` and ``y2`` above ``y1``. | ||
|
|
||
| .. code-block:: python |
There was a problem hiding this comment.
| .. code-block:: python | |
| .. plot:: |
On further discussion, I think this needs a bit more thought.
If it helps come up with names, it appears that the same problem occurs with stacked histograms. For example, if you add a legend to the histogram with multiple data sets example, then you get the following: As you can see, the side-by-side plots appear to be correct (at least for LTR readings). Somehow the stack step is 'right', but stacked bar is reversed. We will likely want to fix these at the same time (though not necessarily the same PR), so a name that works for both would be good. |
Did a quick look and plotly and ggplot both put this kinda thing as an attribute on/method to legend, and they name it |
Wow, great thinking! 🥇 We should definitively have that option on legends. It's not only solving the issue for all the above cases and e.g. I would even go so far to say that we don't need such capability on the individual plotting functions. |
|
a) it would be nice if the draw order were consistent. b) I can understand where the OP is coming from in wanting the legend to be stacked the same way the histograms would be stacked, from top to bottom. However, I would personally expect the opposite, where the first entry of the legend to be the bottommost in the stack. Perhaps more obviously, if the stacked bars were instead horizontal, I'd expect the top entry of the legend to correspond to the left-most element in the stack. Given that there is ambiguity in what people would expect, I'm personally somewhat in favour of this just being a legend keyword helper that basically does |


PR Summary
This will does not alter the order in which stackplot elements are show
on the axes, colors are used, labels are assigned, etc. It is only
(meant to) change the order in which handles are stored in the axes
object and thus in which legend entries appear by default. With this
change the top most entry in the legend should be the top most plotted
stack plot component.
In an example (derived from https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/stackplot_demo.html)
In the example, the bottom most component of the stackplot is 'Fibonacci', yet by default 'Fibonacci' will be the top most entry in the legend. This reverse order causes mental overhead when reading a plot and becomes even more problematic for colorblind readers or once the color pallet is cycled through more than once.
I find the example in https://codeyarns.com/tech/2019-09-12-how-to-reverse-order-of-legend-in-matplotlib.html insufficient to address that inconvenience as the fix is needed for every usage and breaks in the example as I only want to affect the order of stackplot elements but the 'staying above' entry should remain where it is in the legend.
I enabled "Allow edits by maintainers".
PR Checklist
pytestpasses).flake8on changed files to check).flake8-docstringsand runflake8 --docstring-convention=all).doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).pytest error