I'd like to be able to save Matplotlib plots and add them directly as vector graphics in Microsoft Word documents. However, the only format supported by Word and Matplotlib both is .eps, and the axis text is completely missing in Word if I try. I'll show you:
Here's a minimal working example script:
import matplotlib.pyplot as plt
import numpy as np
axes = plt.gca()
data = np.random.random((2, 100))
axes.plot(data[0, :], data[1, :])
- Here's the image I get if I save the plot as .png using the figure's toolbar
- Here's the image I get if I save the plot as .eps and insert it into Word.
Apparently, the way that Matplotlib saves text in .eps files is incompatible with the way that Word reads text from .eps files. The exported .eps files look fine in PS_View.
I can think of two workarounds, but I don't know how to implement them or if it is at all possible in Matplotlib:
- Vectorise the text so that it is embedded as paths. This is supported by Matplotlib's SVG backend by setting the rcParam 'svg.fonttype' to 'path', but it doesn't seem directly supported by the ps backend. This would be the ideal workaround. Is there any way to do this?
- Rasterise only the text when exporting as .eps. This would be a less ideal workaround. Can this be done?
.eps
file in the latest Microsoft Word (2016) on Mac and it now appears to display the text correctly. – Pendentsavefig()
? – Claus.svg
and later I convert it to.emf
using a free software called Inkscape. – Blanchette