Conversation
lib/matplotlib/axes/_axes.py
Outdated
| # draw the whiskers | ||
| whiskers.append(do_plot(whis_x, whislo_y, **whisker_kw)) | ||
| whiskers.append(do_plot(whis_x, whishi_y, **whisker_kw)) | ||
| whiskers.append(do_plot(whis_x, whislo_y, **whisker_kw, label="_nolegend_")) |
There was a problem hiding this comment.
This should be done as
whisker_kw.setdefault('label', '_nolegend_)
or similar where we generate/accept these dictionaries. As proposed this will fail with a TypeError for any user who is currently passing label though.
story645
left a comment
There was a problem hiding this comment.
might also want to confirm that the patch properties are as expected, eg. color.
What happens if you set a label on those elements?
Setting a label to an element like whiskers or caps will revert the next 2 handles into lines. In this case, |
|
We have a The fundamental problem is that calling The brittleness comes from the logic of "I have been given N strings, let me find the first N artists in the axes that I know how to make legend entries for and use those!". By setting The other ways of making legends (either passing both artists and strings ("use these labels for those artists"), passing a list of artists ("ask these artists what their label should be and then put in legend"2 or calling with no arguements ("find anything that has a suitable label and put it in the legend") are all significantly better APIs (easier to understand and not brittle). If the user set a label on the whiskers, it is presumably because they are doing |
I've implemented this idea so now we can call |
|
Talked about this on the call. We like the implementation, but it needs a rebase. |
|
@saranti Did you mean to close this? |

PR summary
Work on this is continued in #27711
Closes #20512. Legend entries in boxplots are now shown as patches instead of thin lines. As explained in #20512 (comment), legend entries were being generated for the box and also for the whiskers, caps, and outliers. This patch prevents entries being created for every artist except the box itself by applying the
label="_nolegend_"argument for those artists.PR checklist