[Matplotlib-users] Artifacts when saving as PDF

2015-04-06 Thread Steven Boada
Getting some strange artifacts when I save a figure as a PDF in 
matplotlib. Here are some screen shots. PDF http://imgur.com/oQDXkWn 
and PNG http://imgur.com/bCw3Fn4.  Any idea why that is happening?


Here is (most of) the source code that makes the plot. I stripped out 
the data generation, because it is long and involved, and doesn't really 
matter. Basically what the script is supposed to do is make a scatter 
plot where the density is below some threshold, and a 2d histogram when 
it is above that threshold. The code seems to work fine, but when I save 
the figure (using savefig in Ipython) it shows up funny.


Thanks.

import pylab as pyl

bins = [50,50]
thresh = 3

xdat = #generate or load some data
ydat = #generate or load some data

hh, locx, locy = pyl.histogram2d(xdat, ydat, 
range=[[-1,4],[-26,-10]], bins=bins)

posx = pyl.digitize(xdat, locx)
posy = pyl.digitize(ydat, locy)

# finds the bins which contain points. posx = 0 for points outside 
range

ind = (posx  0)  (posx = bins[0])  (posy  0)  (posy = bins[1])
# values of histogram with points in the bins.
hhsub = hh[posx[ind] - 1, posy[ind] - 1]

xdat1 = xdat[ind][hhsub  thresh] # low density points
ydat1 = ydat[ind][hhsub  thresh]
hh[hh  thresh] = pyl.nan # fill the areas with low density by NaNs

pyl.scatter(xdat1, ydat1, s=20, c='0.8')
pyl.imshow(pyl.log10(hh.T), cmap='gray_r',
extent=pyl.array([[-1,4],[-26,-10]]).flatten(), 
interpolation='none')


pyl.show()

--

Steven Boada

Doctoral Student
Dept of Physics and Astronomy
Texas AM University
bo...@physics.tamu.edu

--
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15utm_medium=emailutm_campaign=VA_SF___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Artifacts when saving as PDF

2015-04-06 Thread Thomas Caswell
This is probaly due to issues with not all of the vector backends
supporting alpha gracefully.

This can be reproduced more simply by

x, y = np.ogrid[-5:5:.1, -5:5:.1]
dd = np.exp(-(x**2 + y**2))
dd[dd  .1] = np.nan

fig, ax = plt.subplots()
ax.imshow(dd, interpolation='none', cmap='gray_r')
plt.savefig('test.pdf')

@steven In the future it is best to report bugs with minimal copy-paste
able examples.

On Mon, Apr 6, 2015 at 5:41 PM Steven Boada bo...@physics.tamu.edu wrote:

  Getting some strange artifacts when I save a figure as a PDF in
 matplotlib. Here are some screen shots. PDF http://imgur.com/oQDXkWn
 and PNG http://imgur.com/bCw3Fn4.  Any idea why that is happening?

 Here is (most of) the source code that makes the plot. I stripped out the
 data generation, because it is long and involved, and doesn't really
 matter. Basically what the script is supposed to do is make a scatter plot
 where the density is below some threshold, and a 2d histogram when it is
 above that threshold. The code seems to work fine, but when I save the
 figure (using savefig in Ipython) it shows up funny.

 Thanks.

 import pylab as pyl

 bins = [50,50]
 thresh = 3

 xdat = #generate or load some data
 ydat = #generate or load some data

 hh, locx, locy = pyl.histogram2d(xdat, ydat, range=[[-1,4],[-26,-10]],
 bins=bins)
 posx = pyl.digitize(xdat, locx)
 posy = pyl.digitize(ydat, locy)

 # finds the bins which contain points. posx = 0 for points outside
 range
 ind = (posx  0)  (posx = bins[0])  (posy  0)  (posy = bins[1])
 # values of histogram with points in the bins.
 hhsub = hh[posx[ind] - 1, posy[ind] - 1]

 xdat1 = xdat[ind][hhsub  thresh] # low density points
 ydat1 = ydat[ind][hhsub  thresh]
 hh[hh  thresh] = pyl.nan # fill the areas with low density by NaNs

 pyl.scatter(xdat1, ydat1, s=20, c='0.8')
 pyl.imshow(pyl.log10(hh.T), cmap='gray_r',
 extent=pyl.array([[-1,4],[-26,-10]]).flatten(),
 interpolation='none')

 pyl.show()

 --

 Steven Boada

 Doctoral Student
 Dept of Physics and Astronomy
 Texas AM universitybo...@physics.tamu.edu

  
 --
 BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
 Develop your own process in accordance with the BPMN 2 standard
 Learn Process modeling best practices with Bonita BPM through live
 exercises
 http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual-
 event?utm_
 source=Sourceforge_BPM_Camp_5_6_15utm_medium=emailutm_
 campaign=VA_SF___
 Matplotlib-users mailing list
 Matplotlib-users@lists.sourceforge.net
 https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15utm_medium=emailutm_campaign=VA_SF___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] I need to force the rounding of x axis limits

2015-04-06 Thread giacomo boffi
INTRO
=

please consider the following code (I'm trying to draw a timeline)

1 from matplotlib import pyplot, patches
2 fig = pyplot.figure()
3 ax = fig.add_subplot('111')
4 ax.add_patch(patches.Rectangle((1933,0.25), 73, 0.5))
5 pyplot.show()

that gives me a plot with the x axis that goes from 0.0 to 1.0,
now consider

  ...
5 ax.set_xlim((1933,1933+73))
6 pyplot.show()

this gives me an x axis that goes _exactly_ from 1933 to 2006,
eventually drawing a line superposed to the lower spine

  ...
5 ax.plot((1933,1933+73),(0,0))
6 pyplot.show()

gives me what I really want, that is an x axis running from 1930 to
2010, with the limits automatically rounded by matplotlib...

(I noted that the extra line forces a rounding also for the y axis
limits, but that's not a problem...)

QUESTION


I want matplotlib to round the limits of the x axis automatically,
when given explicitly the lower and upper limits of the data, how to?

Thank you in advance

-- 
We have met the enemy and he is us.
--- Pogo.


--
BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT
Develop your own process in accordance with the BPMN 2 standard
Learn Process modeling best practices with Bonita BPM through live exercises
http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_
source=Sourceforge_BPM_Camp_5_6_15utm_medium=emailutm_campaign=VA_SF
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users