Issue
In some pdf viewers such as Preview on OSX, plots made with matplotlib
's pcolor have white lines (see image below). How can I get rid of them?
The source code is very simple (choose any data for x
,y
,z
):
import matplotlib
matplotlib.use("pdf")
import matplotlib.pyplot as pl
pl.figure()
pl.pcolormesh(x,y,z,cmap="Blues",linewidth=0)
pl.savefig("heatmap.pdf")
Solution
The comments have a good solution that utilizes imshow
. When imshow
is not appropriate for the input data (e.g. it is not uniformly spaced) this generally solves this problem,
pcol = pl.pcolormesh(x,y,z,cmap="Blues",linewidth=0,)
pcol.set_edgecolor('face')
If that approach does not reduce the lines sufficiently, you can also try this:
pl.pcolormesh(x,y,z,cmap="Blues",linewidth=0,rasterized=True)
In addition to reducing the lines between squares this approach also tends to reduce file size a bit, which is sometimes useful. In this case you may want to tune the dpi
setting when saving (e.g. pl.savefig("heatmap.pdf", dpi=300)
) until you get something that is satisfactory.
Answered By - farenorth
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.