Skip to content

plt.hist chooses improper range when using string-based bin options #8636

Closed

Description

@pollackscience

plt.hist range bug

When using plt.hist with multiple input data sets, not supplying a range, and using a string-based binning option ('auto', for example), the range determined will cut off the later datasets and only fully include the first.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

data = np.random.normal(0, 1, size=1000)
data2 = np.random.normal(3, 1, size=1000)
data3 = np.random.normal(6, 1, size=1000)

plt.hist([data, data2, data3], bins='auto', histtype='stepfilled', stacked=False)

Actual outcome
bad_hist

Expected outcome
This is the plot using the bin-edges as determined by np.histogram using the following code:

_, be = np.histogram([data, data2, data3], bins='auto')
plt.hist([data, data2, data3], bins=be, histtype='stepfilled', stacked=False)

good_hist

Matplotlib version

  • Operating System: OSX 10.10.5
  • Matplotlib Version: 2.0.1
  • Python Version: 2.7.13
  • Jupyter Version (if applicable): 4.0.6
  • Other Libraries:

Python installed via Homebrew, all python packages installed via pip.

Activity

  1. added a commit that references this issue on May 18, 2017
    cc55b33
  2. tacaswell commented on May 18, 2017

    @tacaswell
    Member

    I have a PR to fix this, but am not super happy about it.

  3. added this to the milestone on May 18, 2017
  4. modified the milestones: , on Sep 24, 2017
  5. bebound commented on Dec 13, 2017

    @bebound

    Is this the same bug? Trying to draw a hist from Series, the second one is the expected output.

    Thank you.
    screen shot 2017-12-13 at 3 46 10 pm

    Source is https://www.kaggle.com/cast42/exploring-features , In [8]:

  6. added a commit that references this issue on Feb 24, 2019
    dab2a16
  7. modified the milestones: needs sorting, v3.1.0 on Feb 25, 2019
  8. added a commit that references this issue on Feb 26, 2019
    8a31633
  9. modified the milestones: v3.1.0, v3.2.0 on Mar 18, 2019
  10. added a commit that references this issue on Mar 19, 2019
    84988fc
  11. modified the milestones: v3.2.0, v3.1.0 on Mar 19, 2019
  12. added a commit that references this issue on Mar 31, 2019
    0c8e9d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions