Skip to content

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

Closed
@pollackscience

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions