Hi,
A while ago, I sent an email around asking about the EPS output from matplotlib. The following example summarizes the problem well:
import matplotlib
matplotlib.use('Agg')
from matplotlib.pyplot import *
import numpy as np
nx,ny = 10,10
image = np.random.random((nx,ny))
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111)
ax.pcolorfast(image)
fig.savefig('plot.eps')
fig.savefig('plot.pdf')
fig.savefig('plot.svg')
This produces files with the following sizes:
600K plot.eps
8.0K plot.pdf
20K plot.svg
The EPS file is much larger because the bitmap is being rasterized to a much higher resolution than a 10x10 grid. However, I eventually figured out that the best way to solve this, assuming that the pixels are square, and that the pixels line up with the axes is:
fig = figure(figsize=(4,4))
ax = fig.add_subplot(111,aspect='equal')
ax.imshow(image)
width = ax.get_position().width * 4
dpi = nx / width
fig.savefig('plot2.eps',dpi=dpi)
which produces
12K plot2.eps
As a temporary solution this works well - essentially matching the DPI to the resolution of the input array.
However, I have one remaining problem. In plot2.eps, the frame border has disappeared. Is this a bug? Does anyone know why this might be happening?
Thanks for any advice,
Thomas