Skip to content

Small issue with hist (probably in mac os x backend) - #408

Merged
mdboom merged 1 commit into
matplotlib:v1.1.xfrom
mdboom:issue408
Nov 8, 2011
Merged

mdboom merged 1 commit into
matplotlib:v1.1.xfrom
mdboom:issue408

Conversation

@mdboom

@mdboom mdboom commented Oct 21, 2011

Copy link
Copy Markdown
Member

(Firstly, this is the kind of bugreport that gets the reporter run out of town with pitch-forks, because it is so trivial. But it scared me a little when I first saw it, so I will report it anyway).

Issue:

When hist is used to plot a histogram with the align='mid' option, the drawing of the histogram on screen is just slightly displaced. A pdf produced with the same plot turns out exactly as expected.

To replicate

import pylab

pylab.figure(figsize=(3,3))
r = pylab.randn(1000000)
pylab.hist(r,bins=100,range=[-3,3],normed=True, align='mid',histtype='stepfilled',color='gray')
x = pylab.linspace(-3,3,100)
y = (1./(2*pylab.pi)**.5)*pylab.exp(-x**2/2)
pylab.plot(x,y,'k')
pylab.setp(pylab.gca(), xlim=[-3,3])

system specs

matplotlib 1.0.1
Mac OS X

This might be an issue with the mac os x backend since pdfs come out fine.

The reason I post this is because I had an analytic derivation for a distribution I was working with and some simulations I was doing. I kept noticing a slight systematic discrepancy between my analytic formula and the monte carlo simulation histogram and started to worry I had missed something in the derivation. But when I printed to pdf, my problem went away, much to my relief.

@mdboom

mdboom commented Jul 27, 2011

Copy link
Copy Markdown
Member

Can you try one of the *Agg backends? (If you don't have another GUI framework installed, you should still be able to set the backend to "Agg" and save PNG files to disk). That would help to determine whether it's Mac OS-X backend-specific.

@kghose

kghose commented Jul 27, 2011

Copy link
Copy Markdown
Author

See this for a screen shot of what I'm talking about http://assorted-experience.blogspot.com/2011/07/small-issue-with-hist.html

@kghose

kghose commented Jul 27, 2011

Copy link
Copy Markdown
Author

Thanks for the quick reply Michael. I just tried with Agg and indeed it is still there. I couldn't see anything popup, but I could save to png as you suggested. I've now putup the png here http://assorted-experience.blogspot.com/2011/07/small-issue-with-hist.html

@mdboom

mdboom commented Jul 27, 2011

Copy link
Copy Markdown
Member

This seems to be related to pixel-snapping. Setting the rcParam "path.snap" to False resolves the issue (but also makes the axes rectangle look blurrier etc.) A better solution is to turn off snapping just for the histogram patch:

hist = pylab.hist(r,bins=100,range=[-3,3],normed=True, align='mid',histtype='stepfilled',color='gray')
for patch in hist[2]:
    patch.set_snap(False)

I think the real fix is probably to not snap histograms -- or re-examine how rounding is done within the pixel-snapping algorithm (which will probably introduce other subtle bugs). Will have to think on that a bit.

@ghost ghost assigned mdboom Jul 27, 2011
mdboom added a commit that referenced this pull request Nov 8, 2011
Small issue with hist (probably in mac os x backend)
@mdboom
mdboom merged commit d2cba84 into matplotlib:v1.1.x Nov 8, 2011
@kghose

kghose commented Mar 4, 2012

Copy link
Copy Markdown
Author

Thanks Michael!
Best
-Kaushik

@mdboom
mdboom deleted the issue408 branch March 3, 2015 18:43
tacaswell added a commit to tacaswell/matplotlib that referenced this pull request Aug 29, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants