2

If I execute the following code, the resulting eps-file does not contain tick labels or axes labels.

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0,2*np.pi,100)
y = np.sin(x)

plt.figure()
plt.plot(x,y)
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.savefig('image.eps', format='eps')

As some additional information: I am using version 4.3.0 of the anaconda distribution and execute my code in Spyder 3.1..2. I tested the two backends TkAgg and Qt5Agg, the result is the same for both.

Any ideas how I can get a correct eps-file?

Alternatively: which other vector graphics format could I use if I want to import into MS Word later?

rmnboss
  • 93
  • 6
  • When I run this, I get the correct eps file with text, etc. – Willem Van Onsem Mar 10 '17 at 15:58
  • Possible duplicate of [Matplotlib labels/titles disappear when exporting in eps format](http://stackoverflow.com/questions/20817455/matplotlib-labels-titles-disappear-when-exporting-in-eps-format) – tafaust Mar 10 '17 at 16:18

2 Answers2

0

So I think that you will find your answer here: https://stackoverflow.com/a/20817722/2402281


It might be the case that your matplotlib backend does not support that operation. You can change the matplotlib backend as follows:

# The default backend; one of GTK GTKAgg GTKCairo GTK3Agg GTK3Cairo
# CocoaAgg MacOSX Qt4Agg Qt5Agg TkAgg WX WXAgg Agg Cairo GDK PS PDF SVG
import matplotlib
matplotlib.use('PS')

or in the matplotlibrc (see the documentation).

Community
  • 1
  • 1
tafaust
  • 1,457
  • 16
  • 32
  • Ah well… I am sorry that did not help. The odds are that the issue is related to your OS or some missing libs because I fail to reproduce the issue using Python 3.6.0 under Linux 4.9.11-1-ARCH GNU/Linux. For the "Alternatively" part in your question, you might have a look at this SO thread: http://stackoverflow.com/a/40250694/2402281 – tafaust Mar 14 '17 at 15:38
0

I encountered same question. The eps file is fine when I plot time series or scatter plot. But when I am plotting geospatial plots using dataframe data, the saved eps file contain no texts and tick labels. So I simply tried:

import matplotlib
matplotlib.use('PS') 
matplotlib.rcParams['text.usetex'] = True

It seems that if you turn the text.usetex to True, it may help. Btw, my Matplotlib is 3.4.2, and operation system is MacOS, and I am using Spyder with python 3.7. Actually I don't know why it sometimes works sometimes does not work, and why it works after I adding matplotlib.rcParams['text.usetex'] = True...It may be because I used alpha when I plot the geospatial plots (like set alpha=5 in ax.scatter). I will put some tiny examples later.

Xu Shan
  • 175
  • 3
  • 11