Skip to content

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

Closed
@joelostblom

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

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