Skip to content

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

@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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy