不同pdf浏览器下的Python-pdf插值

2024-09-27 23:38:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我用imshow(matplotlib 2.2.3)创建了两个python(版本2.7.15)绘图,一个用interpolation='none',一个用'interpolation'='nearest',请参见下面的代码。'none'pdf文件在Evince 3.20.2(和Acrobat Reader DC 2019.010.20069)下显得很清晰,但在Apple Previewer下非常模糊。在Evince和Apple下,'nearest'pdf看起来有点模糊,像素大小不同。为'none''nearest'创建一个rasterized=True图(直接在imshow)会产生类似于rasterized=False 'nearest'的结果。用dpi=1000而不是dpi=100保存不会影响'none'(甚至相同的文件大小),但会改善'nearest'的模糊性,并且像素的大小会变得更相等。然而'nearest'仍然比证据'none'稍微模糊。你知道吗

默认情况下,Apple Previewer似乎使用了'bilinear'插值(至少对于'none'),我认为这是一个糟糕的默认值(与'nearest'相比),尤其是在当前版本中,您无法(直接)更改它。所以我需要更改python方面的参数。我想避免pcolormesh的情节。任何默认的方式来获得“完美”夏普imshow生成的pdf文件为不同的pdf观众?你能用'none'实现这个目标吗?是高dpi的'nearest'?你知道吗

import numpy as np
import matplotlib
import matplotlib.pyplot as plt

pdf_dpi = 100

np.random.seed(100)
a = np.random.rand(100,50)

plt.imshow(a, cmap='binary', aspect='auto', interpolation='none', origin='lower')
plt.title('imshow, interpolation: none')
plt.savefig('/home/proxauf/test_pdf_plot_interpolation/imshow_none.pdf', dpi=pdf_dpi)
plt.close()

plt.imshow(a, cmap='binary', aspect='auto', interpolation='nearest', origin='lower')
plt.title('imshow, interpolation: nearest')
plt.savefig('/home/proxauf/test_pdf_plot_interpolation/imshow_nearest.pdf', dpi=pdf_dpi)
plt.close()

Tags: 文件import版本noneapplepdfmatplotlibnp

热门问题