Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

timhoffm
Copy link
Member

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 and patch.force_edgecolor. However, they are too broad in their scope and may unwantedly change other patches as well. This justifies the intoduction of a dedicated hist.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

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)

@timhoffm timhoffm added this to the v3.1 milestone Nov 25, 2018
@jklymak
Copy link
Member

jklymak commented Nov 25, 2018

Ok but where does it stop? The line widths are pretty wide by default.

Personally -1 on the visual clutter of the bar outlines.

@timhoffm
Copy link
Member Author

timhoffm commented Nov 25, 2018

Ok but where does it stop?

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 hist.linewidth.

Personally -1 on the visual clutter of the bar outlines.

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.

@jklymak
Copy link
Member

jklymak commented Nov 25, 2018

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,
Copy link
Member

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).

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member Author

@timhoffm timhoffm Dec 1, 2018

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.

@timhoffm timhoffm force-pushed the rcparam-hist-edgecolor branch from d35fe71 to 1295778 Compare December 1, 2018 17:43
@timhoffm timhoffm changed the title Add rcParam hist.edgecolor Add rcParams hist.edgecolor, hist.linewidth Dec 1, 2018
@timhoffm timhoffm force-pushed the rcparam-hist-edgecolor branch 6 times, most recently from 3fbfc83 to 51aea55 Compare December 1, 2018 18:41
@timhoffm
Copy link
Member Author

timhoffm commented Dec 1, 2018

hist.linewdith rcparam added.

@timhoffm timhoffm force-pushed the rcparam-hist-edgecolor branch from 51aea55 to 2956258 Compare December 2, 2018 09:41
@jklymak
Copy link
Member

jklymak commented Dec 3, 2018

Failing py 3.5 tests for some reason 😢

@timhoffm
Copy link
Member Author

timhoffm commented Dec 3, 2018

Ok, waiting for 3.5 removal (#12358). 😄

@timhoffm timhoffm force-pushed the rcparam-hist-edgecolor branch from 2956258 to 4ecbffb Compare December 5, 2018 23:09
@timhoffm
Copy link
Member Author

timhoffm commented Dec 5, 2018

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.
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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)

Copy link
Member Author

@timhoffm timhoffm Feb 17, 2019

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`.
Copy link
Contributor

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.

Copy link
Contributor

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...)

@timhoffm
Copy link
Member Author

Need some time to go through the review.

@tacaswell tacaswell modified the milestones: v3.1.0, v3.2.0 Feb 24, 2019
@tacaswell
Copy link
Member

Punting to 3.2, please re-milestone if you disagree @timhoffm .

@timhoffm timhoffm modified the milestones: v3.2.0, v3.3.0 Aug 7, 2019
@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 2, 2020
@jklymak jklymak marked this pull request as draft July 23, 2020 16:10
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 21, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Aug 23, 2021
@timhoffm timhoffm modified the milestones: v3.6.0, unassigned Apr 30, 2022
@story645 story645 modified the milestones: unassigned, needs sorting Oct 6, 2022
@github-actions
Copy link

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.

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants