Skip to content

Feature request: show bars in plt.hist #12874

Closed as not planned
Closed as not planned

Description

@rosgori

Feature request

Summary

With the new style of plotting (after version 1.5), you cannot distinguish the bars on plt.hist. Take for example the old way:

import matplotlib.pyplot as plt
import random

l_n = []
for _ in range(2000):
    l_n.append(random.betavariate(5, 25))

with plt.style.context('classic'):
    plt.hist(l_n, bins=20)
    plt.show()

Unfortunately, I cannot upload images. Nevertheless, you can see the bars. Now, this:

plt.hist(l_n, bins=20)
plt.show()

You only see the silhouette of the histogram, not the bars. An easy way to solve this:

plt.hist(l_n, bins=20, edgecolor='w')
plt.show()

edgecolor='w' would be the default option (I would prefer white because it looks good with all the styles). What do you think?

By the way, if you want to compare with other software, I think all of them show bars. And a quick search shows...

Matplotlib version

  • Operating system: Ubuntu 16.04.5 LTS
  • Matplotlib version: 3.0.1
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.6.6
  • Jupyter version (if applicable): 7.1.1
  • Other libraries:
  • How I installed matplotlib: conda

Activity

  1. jklymak commented on Nov 24, 2018

    @jklymak
    Member

    plt.hist(l_n, bins=20, edgecolor='w') works fine, so are you asking that this be the default? I'd not particularly support that. On the other hand maybe a hist.edgecolor rcparam could be considered (I didn't see one, though you can patch.force_edgecolor.

  2. anntzer commented on Nov 24, 2018

    @anntzer
    Contributor

    Discussed #12493 as well.

  3. rosgori commented on Nov 25, 2018

    @rosgori
    Author

    Yes, I agree with you that edgecolor='w' might not be the best option.

    Besides, I didn't know that a change in these two lines

    #patch.edgecolor : black ## if forced, or patch is not filled
    #patch.force_edgecolor : False ## True to always use edgecolor

    achieves what I am looking for.

    So... do you think this feature should be included in matplotlib (either with a new parameter hist.edgecolor or a change in patch.force_edgecolor or with another solution)?

  4. timhoffm commented on Nov 25, 2018

    @timhoffm
    Member

    I agree that bars in histograms should be visually separate. The current default behavior is not good.

    A hard coded default edgecolor='w' can break styles.

    Rcparams patch.edgecolor and patch.force_edgecolor are too global in their scope.

    Therefore a hist.edgecolor rcparam is the reasonable way to go.

  5. github-actions commented on Nov 3, 2023

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  6. added
    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.
    on Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: closed as inactiveIssues closed by the "Stale" Github Action. Please comment on any you think should still be open.status: inactiveMarked by the “Stale” Github Actiontopic: histtopic: rcparams

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions