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

Error autoscaling histogram with histtype='step' #841

Closed
joshualande opened this issue Apr 18, 2012 · 8 comments
Closed

Error autoscaling histogram with histtype='step' #841

joshualande opened this issue Apr 18, 2012 · 8 comments

Comments

@joshualande
Copy link

I am running into problems where histograms are not autoscaling correctly.

Below is a very simple example which reproduces this problem:

import pylab as P
P.hist([3000,3010, 3012], histtype='step')
P.savefig('test.pdf')

When I run this example using matplotlib v1.1.0 or using the absolute latest version of matplotlib, I obtain an axes which varies from 3000<x<3012 and 0<y<3000 with no visible histogram.

When I add (before saving the plot) the line:

P.gca().set_ylim(ymax=2.1)

I get a reasonable axes range and can see the histogram.

I also get a reasonable axes range when I remove the command histtype='step' or when I use matplotlib v1.0.0.

Thanks for your help,

Joshua

@taldcroft
Copy link

I see a (probably) related problem with the normed option and histtype='step' (or stepfilled).

% ipython --pylab

In [1]: hist(normal(100, 15, 10000), normed=True, histtype='step')
Out[1]: 
(array([  1.68129565e-05,   1.68129565e-04,   1.41228835e-03,
         7.06144175e-03,   1.79730506e-02,   2.50933376e-02,
         2.09405374e-02,   9.12943541e-03,   1.96711592e-03,
         3.02633218e-04]),
 array([  33.23287027,   45.12845802,   57.02404577,   68.91963352,
         80.81522128,   92.71080903,  104.60639678,  116.50198453,
        128.39757228,  140.29316004,  152.18874779]),
 <a list of 1 Patch objects>)

This produces a plot with y-axis from 0 to 40. Without histtype='step' I get the expected plot with y limits from 0 to 0.030.

I've seen this with matplotlib 1.1.0 on CentOS-5 x86_64 and matplotlib 1.0.1 on Snow leopard. I think that 1.0.0 was OK (or maybe 0.99.1), since I have old code with histtype that used to work.

@ycopin
Copy link

ycopin commented Jun 5, 2012

I guess I found the bug: in matplotlib/axes.py:7729 (for matplotlib 1.1.0), it says:

minimum = min(bins)

which is just wrong. Replace this line with something like:

minimum = min( min(m) for m in n )

fix the bug.

BTW, few lines below, the code:

                for m in n:
                    ymin = np.amin(m[m!=0]) # filter out the 0 height bins

does not make much sense either, but I have no idea what it is supposed to do anyway...

@ycopin
Copy link

ycopin commented Oct 5, 2012

Could this be corrected for matplotlib 1.2?

efiring added a commit to efiring/matplotlib that referenced this issue Oct 14, 2012
efiring added a commit that referenced this issue Oct 14, 2012
Fix by Yannick Copin for hist autoscaling bug; closes issue #841
@tacaswell
Copy link
Member

This looks like at has come back (the code from first report is still generates a graph with strange limits).

@neggert Can you take a look at this?

@neggert
Copy link
Contributor

neggert commented Oct 27, 2013

Sure. There's another bug a colleague pointed out to me that I've been wanting to look at, so I can work on these both tomorrow.

@neggert
Copy link
Contributor

neggert commented Oct 27, 2013

@tacaswell I can't seem to reproduce this on either v1.3.x or master. I get a plot with a y-axis that goes from 0 to 1 (which isn't great either because you can't see the line, but it's not the same issue).

@tacaswell
Copy link
Member

Yeah, I didn't read carefully enough (parsed 'bad limits', not what sort of bad limits).

This looks like it is actually an issue with the generic auto-limit code. Sorry for the noise.

@mdboom
Copy link
Member

mdboom commented Jan 27, 2014

Seems like the original issue has been fixed along the way. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants