python - Converting text in Matplotlib when exporting .eps files -


i'd able save matplotlib plots , add them directly vector graphics in microsoft word documents. however, format supported word , matplotlib both .eps, , axis text missing in word if try. i'll show you:

here's minimal working example script:

import matplotlib.pyplot plt import numpy np  axes = plt.gca() data = np.random.random((2, 100)) axes.plot(data[0, :], data[1, :]) 

apparently, way matplotlib saves text in .eps files incompatible way word reads text .eps files. exported .eps files fine in ps_view.

i can think of 2 workarounds, don't know how implement them or if @ possible in matplotlib:

  1. vectorise text embedded paths. supported matplotlib's svg backend setting rcparam 'svg.fonttype' 'path', doesn't seem directly supported ps backend. ideal workaround. there way this?
  2. rasterise only text when exporting .eps. less ideal workaround. can done?

as sebacastroh points out, 1 can save matplotlib figure svg using plt.savefig() , use inkscape conversion between svg , emf. enhanced meta files (emf) read office programm.
can automated, so

import matplotlib.pyplot plt import numpy np subprocess import call  def saveemf(filename):     path_to_inkscape = "d:\path\to\inkscape\inkscape.exe"     call([path_to_inkscape, "--file", filename,  "--export-emf",  filename[:-4]+".emf" ])  axes = plt.gca() data = np.random.random((2, 100)) axes.plot(data[0, :], data[1, :]) plt.title("some title") plt.xlabel(u"some x label [µm]") plt.ylabel("some y label")  fn = "data.svg" plt.savefig(fn) saveemf(fn) 

it may make sense save saveemf() function externally in module have @ hand.


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -