From: Thomas C. <tca...@gm...> - 2015-04-07 01:47:35
|
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...@ph...> 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 A&M Uni...@ph... > > ------------------------------------------------------------ > ------------------ > 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_15&utm_medium=email&utm_ > campaign=VA_SF_______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users > |