-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Add rcParams hist.edgecolor, hist.linewidth #12884
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
base: main
Are you sure you want to change the base?
Conversation
Ok but where does it stop? The line widths are pretty wide by default. Personally -1 on the visual clutter of the bar outlines. |
As long as the option handling is manageable and there's a good reason to make something configurable, I don't have a problem adding more rcParams. In particular, I would not be opposed to
It was mentioned in #12874 (comment) that most histogram plots seem to have visually distinct bars. Whether we like that and if we want that as the default style is a separate discussion, which I'm intentionally not going into with this PR. However, I acknowledge, that it's a common look and we should thus make it possible to achieve it using styles. This is what the PR is about. |
This seems fine, but if you are up to it, a linewidth rcParam would also make sense since that will be the next ask.. |
@@ -6724,7 +6741,8 @@ def hist(self, x, bins=None, range=None, density=None, weights=None, | |||
height = m | |||
patch = _barfunc(bins[:-1]+boffset, height, width, | |||
align='center', log=log, | |||
color=c, **{bottom_kwarg: bottom}) | |||
color=c, edgecolor=ec, |
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.
This gets into the color
, facecolor
, edgecolor
confusion. Probably should be clear in the doc of color
what the color means, and it'd be nice if it was consistent w/ the other instances of this. (Yes this ambiguity predated this PR due to the fact that patch kwargs are passed through to patch).
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'll look into linewidth and the color descriptions.
It's even a bit worse since the meaning of color
depends on the histtype
. For histtype='bar'
and histtype='stepfilled'
it's the facecolor. For histtype='step'
it's the edgecolor and the edgecolor
is ignored. Even though, this behavior is confusing, I intentionally did not touch it in this PR to keep backward compatibility.
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.
Fair enough but the color doc string could be made more specific. When we didn’t have an edgecolor kwarg we could assume some expertise in the part of the user who were able to drill down to the patch kwargs. But with that kwarg it’s going to lead to confusion.
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.
Going to work in it.
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.
Reworked the documentation of the color parameter.
d35fe71
to
1295778
Compare
3fbfc83
to
51aea55
Compare
|
51aea55
to
2956258
Compare
Failing py 3.5 tests for some reason 😢 |
Ok, waiting for 3.5 removal (#12358). 😄 |
2956258
to
4ecbffb
Compare
Rebased after python 3.5 was removed in #12358. |
linewidth : float, optional | ||
The linewidth of the bar edges. If not given, use | ||
:rc:`hist.linewidth`. If that is *None*, the default | ||
:rc:`patch.linewidth` is used. |
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.
is that fallback true even for histtype=step?
*x*, there must be one color per dataset. If *None* the | ||
standard line color sequence is used. | ||
|
||
The *color* parameter is overridden if *facecolor* is given. |
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.
the facecolor argument is mentioned nowhere else I think?
- For filled *histtype*\s ('bar', 'barstacked' and 'stepfilled'): | ||
|
||
The facecolor of the bars. If providing multiple datasets to | ||
*x*, there must be one color per dataset. If *None* the |
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.
or is it broadcasted? (dunno)
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.
Nope, the description is correct:
if color is None:
...
else:
color = mcolors.to_rgba_array(color)
if len(color) != nx:
raise ValueError(
"color kwarg must have one color per data set. %d data "
We could broadcast, but that's beyond this PR.
edgecolor : color or array_like of colors, optional | ||
The edgecolor of the bars. If providing multiple datasets to | ||
*x*, you can either pass a single edgecolor for all datasets or | ||
one edgecolor per dataset. If not given, use :rc:`hist.edgecolor`. |
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.
... unless histtype=step in which case it's a single color?
The linewidth of the bar edges. If not given, use | ||
:rc:`hist.linewidth`. If that is *None*, the default | ||
:rc:`patch.linewidth` is used. | ||
|
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 guess kwargs (just below) Patch properties if histtype = bar but Line2D properties if histtype = step?
I think the discussion above about color/edgecolor/facecolor is quite confusing. I would suggest instead moving everything under the doc entry for **kwargs
(which should read "Patch properties if histtype=bar; Line2D properties if histtype=step") and then have an additional paragraph like (haven't checked factual accuracy...)
Color specification follows the underlying artist type.
If using Patches (histtype=bar), the patch edge colors can be set using edgecolors (a single or list of colors), the patch face colors can be set using facecolors (...), and both can be simultaneously set using color (...); the defaults are ...
If using Line2D (histtype=step), ...
(and whatever's right for stepfilled too...)
Need some time to go through the review. |
Punting to 3.2, please re-milestone if you disagree @timhoffm . |
Since this Pull Request has not been updated in 60 days, it has been marked "inactive." This does not mean that it will be closed, though it may be moved to a "Draft" state. This helps maintainers prioritize their reviewing efforts. You can pick the PR back up anytime - please ping us if you need a review or guidance to move the PR forward! If you do not plan on continuing the work, please let us know so that we can either find someone to take the PR over, or close it. |
PR Summary
As discussed in #12874 and part of #12493, the mpl2 style merges all histogram bars into a single area because the patches do not have an edge by default.
One can modify the default behavior by setting the rcParams
patch.edgecolor
andpatch.force_edgecolor
. However, they are too broad in their scope and may unwantedly change other patches as well. This justifies the intoduction of a dedicatedhist.edgecolor
rcParam.For now, the default is left to
None
so that the default matplotlib behavior is unchanged, but style authors can already make use of the param. If and when we should change the matplotlib default is left for another discussion.PR Checklist