PDF python 图模糊 - 图像插值?

PDF python plot is blurry - image interpolation?

提问人:bproxauf 提问时间:1/18/2019 更新时间:1/18/2019 访问量:1685

问:

我想将 python 生成的 pdf 绘图包含在 Overleaf Latex 文档中。但是,图像看起来模糊。下面是一个最小的例子。我用 imshow 生成两个图,一个用 ,一个用 。使用的版本是 Python 2.7.15matplotlib 2.2.3。interpolation='none'interpolation='nearest'

使用 pdf-viewer evince 3.20.2,imshow_none.pdf具有非常清晰的像素,而imshow_nearest.pdf显示模糊的像素边缘,并且像素大小可能不同。在 Firefox 52.5.0 下的 Overleaf 内置 pdf 查看器中,一切都反之亦然,模糊更严重。从 Overleaf 下载编译的 pdf 时,情况与查看 evince 下的文件时一样。Png 屏幕截图和叶子乳胶文件在下面找到。

我不是插值方面的专家。pdf 查看器是否使用 matplotlib 插值参数或他们自己的插值方法?为什么一旦模糊的图像被imshow_none.pdf,一次imshow_nearest.pdf?插值方法是否以某种方式存储在 pdf 中?在标签中?如何读出此信息?有什么方法可以创建一个在 evince 和 Overleaf 下都很清晰的文件吗?

Evince: imshow, interpolation='none'
Evince: imshow, interpolation='nearest' Overleaf: imshow, interpolation='nearest' Overleaf: imshow, interpolation='none'

Python 代码:

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

print sys.version
print matplotlib.__version__

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')
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')
plt.close()

乳胶代码:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}

\begin{document}

\begin{figure}[H]
\centering
\includegraphics{imshow_none.pdf}
\end{figure}

\begin{figure}[H]
\centering
\includegraphics{imshow_nearest.pdf}
\end{figure}

\end{document}
python pdf matplotlib latex 插值

评论

2赞 ImportanceOfBeingErnest 1/18/2019
相关:issues/12065
0赞 bproxauf 1/18/2019
谢谢你的链接。这是非常有用的:)
0赞 bproxauf 1/19/2019
有没有办法告诉哪个 pdf 阅读器强制“最近”插值?因为python生成的“最近”图像在使用Evince查看时仍然模糊。
0赞 ImportanceOfBeingErnest 1/19/2019
不确定,这取决于pdf阅读器。也许在处理苹果特定问题的网站上提出问题?
0赞 Jody Klymak 1/19/2019
如果您使用(如果需要),我认为图像不会模糊。您可能希望栅格化 pcolor(在 kwargs 列表中)。pcolormeshax.set_aspect(1)rasterized=True

答: 暂无答案