-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Boxplot: Median line is now bound within the box for all linewidths #23335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Boxplot: Median line is now bound within the box for all linewidths #23335
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a while, please feel free to ping @matplotlib/developers
or anyone who has commented on the PR. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
medianprops['solid_capstyle'] = 'butt' | ||
|
||
# put the mean and median line below the box for visual improvement | ||
zdelta = -0.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this lead to that the lines disappear if the box is colored?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right. The lines disappear due to the change of the zdelta. I am not sure what the intended result should be. As you described (#19409 (comment)), the mean and median lines have a different cap style. How should the desired result look?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My comment there did clearly not take filled boxes into account...
I think that is really the main problem here: what should it look like? I've googled a bit and there seems to be no real consensus if the lines should extend in a certain way.
Anyway, I guess that there are two options here:
- simply change the caps as you currently do and do not change the zorder.
- use something like
clip_on=True, clip_path=box
to the line (wherebox
is the actual box object). If that is the right one is hard to say though. This should at least work for the median line. (The mean line may disappear if it is not in the box though.) However, I think that this will give exactly the same result as it is clipped using the "theoretical zero width line" rather than the actual line.
So probably just reverting the zorder change is enough.
If you can provide an image of the results (e..g using any of the examples in #19409, possibly with exaggerated line widths), that would simplify the review. (Just paste it in a comment.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would actually strongly consider an image test here so we can codify what this should look like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the detailed answer. I will go with option 1 then.
Also I will read further into the image tests and provide a test for it.
zdelta = 0.1 | ||
# Use 'butt' as the default capstyle to avoid a visual overlap of | ||
# the median line and the boxplot | ||
if medianprops.get('solid_capstyle') is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if medianprops.get('solid_capstyle') is None: | |
if medianprops is None or medianprops.get('solid_capstyle', None) is None: |
This is causing the test failure. Also, providing a default option for get avoid an error in case the element is not there.
Regarding the test, I think it makes sense. |
Other changes: - Update `.gitignore` to ignore `venv/` in commit - Fixed a small typo in `bxp()` - Added a new test for the median line (from PR matplotlib#23335)
Closing in favour of #26462 |
Closes #19409. - Set the default capstyles (solid and dashed) for median and mean lines in boxplots to "butt". I also modieifed the behaviror for setting the capstyle for median lines to obey the user's preference instead of overriding it. - The boxplot PDFs were using the wrong capstyle, so I modified the references to use the butt captyle. - Fixed a small typo in `bxp()` - Added a new test for the median line (from PR #23335) Co-authored-by: Elliott Sales de Andrade <[email protected]>
PR Summary
Fixes #19409
When changing the
linewidth
property of the median line in boxplots, the line will extend beyond the box width.I added a default capstyle preventing this from happening. I also changed the zdelta, so that the median and mean lines no longer overlap the box's border.
I would like to get further feedback, since this is my first contribution. I am also not sure if I need to document this bugfix somewhere.
PR Checklist
Tests and Styling
pytest
passes).flake8-docstrings
and runflake8 --docstring-convention=all
).Documentation
doc/users/next_whats_new/
(follow instructions in README.rst there).doc/api/next_api_changes/
(follow instructions in README.rst there).