提高点绘图精度

时间:2017-04-24 13:32:59

标签: python matplotlib

当绘制具有非常接近的值的点时,有时具有不同值的点似乎具有相同的值。在下面的图片中,所有六个点都有不同的纵坐标值,但似乎点2,3和点4,5,6具有相同的值。

我知道这是解决问题(由于此处未详述的原因,我无法增加)。不过,有没有可能告诉matplotlib更精确地绘制这些点?

enter image description here

MWE:

import matplotlib
from matplotlib import pyplot as plt

coor = [[0.5,0.525,0.55,0.575,0.6,0.625],[0.5,0.501,0.502,0.503,0.504,0.505]]

fig = plt.figure(figsize=(3.5,3.5))
plts=fig.add_subplot(1,1,1)
fig.subplots_adjust(left=0.01, right=0.99, bottom=0.01, top=0.99, hspace=0, wspace=0)

plts.set_xlim([0,1])
plts.set_ylim([0,1])
plts.get_xaxis().set_visible(False)
plts.get_yaxis().set_visible(False)

grph = plts.scatter(coor[0],coor[1],facecolor='k',marker='o',lw=0,s=25)
fig.savefig('test.png', bbox_inches='tight', dpi=100)

2 个答案:

答案 0 :(得分:3)

问题来自100 dpi的解决方案。由于点'位置需要是1个像素的倍数,它们的位置看起来是离散的。

保存图片时,您当然可以增加dpi。以下是原始图片,以100 dpi保存,显示出不良行为。

enter image description here

以下是以300 dpi保存的照片,然后下采样到与原始照片相同的尺寸。

enter image description here

如果你选择这样的数字大小 figsize*saved_dpi/desired_dpi == integer结果会更好;但是你需要避免使用bbox_inches='tight'

答案 1 :(得分:0)