Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
joelostblom opened this issue May 7, 2015 · 2 comments
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Milestone

Comments

@joelostblom
Copy link
Contributor

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

@joelostblom joelostblom changed the title specifying histplt.hist Specifying histtype='stepfilled' and normed=True when using plt.hist causes the ymax to be set incorrectly May 7, 2015
@joelostblom joelostblom 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 May 7, 2015
@tacaswell tacaswell added this to the next point release milestone May 7, 2015
@tacaswell tacaswell added the Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues label May 7, 2015
@tacaswell
Copy link
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.

@tacaswell tacaswell modified the milestones: proposed next point release, next point release Jul 16, 2015
CrazyKsv added a commit to CrazyKsv/matplotlib that referenced this issue Mar 16, 2016
CrazyKsv added a commit to CrazyKsv/matplotlib that referenced this issue Mar 16, 2016
CrazyKsv added a commit to CrazyKsv/matplotlib that referenced this issue Mar 16, 2016
This was referenced Mar 16, 2016
@ghost ghost mentioned this issue Mar 17, 2016
@QuLogic QuLogic mentioned this issue Nov 24, 2016
2 tasks
@QuLogic
Copy link
Member

QuLogic commented Dec 11, 2016

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

@QuLogic QuLogic closed this as completed Dec 11, 2016
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Dec 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Easy https://matplotlib.org/devdocs/devel/contribute.html#good-first-issues
Projects
None yet
Development

No branches or pull requests

3 participants