5

I'm trying to save a matplotlib figure in eps format, but when I use savefig(), the labels and titles all disappear. It works fine with every other type of output, so I'm not sure what's going wrong.

import numpy as np
import matplotlib.pyplot as plt

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

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(data)
plt.title('Title')
plt.xlabel('x axis')
plt.ylabel('y axis')

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

The .png file I get from this is properly labeled (plt.show() also looks okay), but the .eps ends up without labels. Any thoughts? (I'm still learning how to use matplotlib, so it might be an easy fix that I'm overlooking...)

Donna
  • 53
  • 1
  • 3

1 Answers1

0

The backend you are using isn't supporting the font package you're using.

Try setting the matplotlib backend to one of the known backends. This must be done before you import matplotlib.

To find out which backend is currently set, see matplotlib.get_backend().

    import numpy as np
    import matplotlib
    matplotlib.use('TkAgg') 
    import matplotlib.pyplot as plt
Myles Baker
  • 3,600
  • 2
  • 19
  • 25
  • 1
    Looks like the backend was already set to TkAgg, which isn't working. I tried switching it to 'PS' since I'm trying to get an .eps output, but the text still isn't there... – Donna Dec 29 '13 at 15:22
  • I would try 'Qt4Agg'. – Myles Baker Dec 29 '13 at 16:13
  • 1
    ACK looks like there was also an issue with my EPS viewing software, which I clearly should have looked into earlier. But using the non-interactive 'PS' backend is working like a charm. Thanks! – Donna Dec 29 '13 at 16:16