Skip to content

Specifying histtype='stepfilled' and normed=True when using plt.hist causes ymax to be set incorrectly #4414

Closed

Description

@joelostblom

The combination of histtype='stepfilled' and normed=True seem to cause some problems with the max ylimit.

import matplotlib.pyplot as plt
import seaborn.apionly as sns
iris = sns.load_dataset('iris')

plt.figure()
for species, species_df in iris.groupby("species"):
    plt.hist(species_df["petal_length"].values, normed=True, histtype="stepfilled")
plt.legend(sorted(iris.species.unique()))

image
Which is not the case when only using histtype='stepfilled'.

plt.figure()
for species, species_df in iris.groupby("species"):
    plt.hist(species_df["petal_length"].values, histtype="stepfilled")

image
Or when only using normed=True.

plt.figure()
for species, species_df in iris.groupby("species"):
    plt.hist(species_df["petal_length"].values, normed=True)

image
It seems like in the erroneous case above, the max of the yaxis is set by the last plotted distribution, which can be tested by changing the order of when the different histograms are plotted.

plt.figure()
iris.loc[iris.species == 'setosa', 'species'] = 'wsetosa'
for species, species_df in iris.groupby("species"):
    plt.hist(species_df["petal_length"].values, normed=True, histtype="stepfilled")
plt.legend(sorted(iris.species.unique()))

image

Activity

  1. changed the title [-]specifying histplt.hist [/-] [+]Specifying histtype='stepfilled' and normed=True when using plt.hist causes the ymax to be set incorrectly[/+] on May 7, 2015
  2. changed the title [-]Specifying histtype='stepfilled' and normed=True when using plt.hist causes the ymax to be set incorrectly[/-] [+]Specifying histtype='stepfilled' and normed=True when using plt.hist causes ymax to be set incorrectly[/+] on May 7, 2015
  3. added this to the milestone on May 7, 2015
  4. added
    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
    on May 7, 2015
  5. tacaswell commented on May 7, 2015

    @tacaswell
    Member

    I suspect that some place there is a ax.set_ylim(max(..)) call which just needs to be changed to an autoscale/limit call, but given that this is hist one can never be sure.

  6. modified the milestones: , on Jul 16, 2015
  7. QuLogic commented on Dec 11, 2016

    @QuLogic
    Member

    This was corrected by #7476 and should be fixed in 2.0.0.
    figure_1

  8. modified the milestones: , on Dec 11, 2016
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

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions