matplotlib的pcolor中的白线 [英] White lines in matplotlib's pcolor

查看:207
本文介绍了matplotlib的pcolor中的白线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在某些pdf查看器中,例如OSX上的Preview,用matplotlib的pcolor绘制的图上有白线(请参见下图).我该如何摆脱它们?

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?

源代码非常简单(为xyz选择任何数据):

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")

推荐答案

注释具有利用imshow的良好解决方案.当imshow不适合输入数据时(例如,它不是均匀分布的),通常可以解决此问题,

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)

除了减少正方形之间的线条外,此方法还倾向于稍微减小文件大小,这有时很有用.在这种情况下,您可能需要在保存时调整dpi设置(例如pl.savefig("heatmap.pdf", dpi=300)),直到获得满意的结果为止.

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.

这篇关于matplotlib的pcolor中的白线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆