I usually create figures using matplotlib. Here is a minimal working example:
def cm2inch(*tupl):
inch = 2.54
if isinstance(tupl[0], tuple):
return tuple(i/inch for i in tupl[0])
else:
return tuple(i/inch for i in tupl)
# matplotlib settings
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from matplotlib.patches import Ellipse, Rectangle
import matplotlib.patches as patches
import numpy as np
plt.rc('text', usetex=True)
plt.rc('font',**{'family':'serif','serif':['Times New Roman']})
params = {'text.latex.preamble' : [r'\usepackage{amssymb}', r'\usepackage{amsmath}']}
plt.rcParams.update(params)
figW = 17.9219/2
figH = 3.5*2.0
fig = plt.figure(figsize=cm2inch((figW, figH)))
x = np.linspace(0.001, 15., 500)
ax1 = fig.add_axes([0.1, 0.1, 0.8, 0.8],
xlabel=r"x-axis",ylabel=r"y-axis")
xr_ = 0.5
ax1.axvspan(5-xr_, 5 xr_, color='C1', alpha=0.2, linewidth=0)
ax1.plot(x, 0.05*(x-5)**2, 'C0', label='cool plot')
ax1.axvline(5, color='C3', dashes=[4,2], lw=1.0)
ax1.legend(fontsize=6, loc=1)
ax1.set_xlim([0, 14.5])
ax1.set_ylim([0,1.1])
ax1.set_xticks([])
ax1.set_xticklabels([])
ax1.set_yticks([0, 1.0])
ax1.set_yticklabels([0, 1])
ax1.tick_params(axis="y",direction="in")
ax1.tick_params(axis="x",direction="in")
yshift_ = 0.1
yshift_2 = 0.3
ax1.text(2*5-2.5, 0.48 yshift_2, r"value", fontsize=8, color='C3', ha='center')
fig.savefig('input.pdf', dpi=1000)
plt.show()
Output (saved as png instead of pdf):
I then want to convert the generated pdf to eps (note that I do not want to create a eps directly, for workflow related reasons).
I have read the following post:
Is there any way to teach Inkscape to convert the Times New Roman font created by matplotlib correctly?
Additional info: I am using Mac OS and I do have Times New Roman installed according to the Font Book.
CodePudding user response:
You can use poppler library to import the pdf by using the --pdf-poppler
option. However, that will convert text to paths.
So you can try with the following command:
inkscape input.pdf --pdf-poppler --export-filename=output.eps