|
From: Steven B. <bo...@ph...> - 2015-04-06 21:40:38
|
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 University bo...@ph... |