2

我想将没有插值的热图导出为 EPS 文件。使用imshow()with interpolation='nearest',如果我导出为 PDF(或 PNG 或 SVG),图像看起来正确,没有插值。但如果我导出为 EPS,它似乎忽略了interpolation='nearest'.

有没有什么方法可以导出为 EPS 而无需插值?

以下是演示导出文件类型差异的示例代码:

import numpy as np
import matplotlib.pyplot as plt

data = np.random.rand(4,4)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(data,interpolation='nearest')

fig.savefig('test.eps')
fig.savefig('test.pdf')
fig.savefig('test.png')
4

1 回答 1

2

较新版本的 matplotlib 接受参数interpolation='none',这可能会产生预期的效果。对于您的代码,这将显示为

import numpy as np
import matplotlib.pyplot as plt

data = np.random.rand(4,4)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(data,interpolation='none')

fig.savefig('test.eps')
fig.savefig('test.pdf')
fig.savefig('test.png')
于 2012-04-17T12:13:23.350 回答