大致代码
import os
import matplotlib.pyplot as plt
import numpy as np
path = os.path.join(os.getcwd(), 'output')
print(path)
os.makedirs(path, exist_ok=True)
path = os.path.join(path, 'sinkcv')
os.makedirs(path, exist_ok=True)
# plt.rcParams['text.usetex'] = True
# plt.rcParams['text.latex.preamble'] = [
# r'\usepackage{amsmath}',
# r'\usepackage{amssymb}']
rc = {"pdf.fonttype": 42, 'text.usetex': True,
'text.latex.preamble': ''.join([r'\usepackage{amsmath}', r'\usepackage{amssymb}'])}
plt.rcParams.update(rc)
if __name__ == '__main__':
p = 0.9
colors = ['cornflowerblue', 'indianred']
markers = ['v', 'o']
linestyles = ['dashed', 'dotted']
# labels = ['$\mathcal{F},\,t=$', '$\mathcal{H},\,t=$']
labels = ['S, t=', 'TI, t=']
markevery = 150
f, ax = plt.subplots(1, 1, figsize=(p * 6, p * 4))
for t, linestyle, marker in zip(scale_l, linestyles, markers):
eps, rho = t * eps_r, t * rho_r
for s, label, color in zip(string_method, labels, colors):
err = np.load(
os.path.join(path, f"error_{s}_sinkhorn_{penalty}_eps{eps}_{dataname}.npy"))
ax.plot(err, c=color, linestyle=linestyle,
label=label + f'{t}',
marker=marker, markevery=markevery)
ax.legend(fontsize=11, ncol=2, columnspacing=0.5, handlelength=2.)
ax.grid()
ax.set_yscale('log')
# ax.set_ylim([1e-6, 1.5])
ax.set_xlabel('Number of Iterations', fontsize=18)
if penalty == 'kl':
ax.set_title('KL entropy', fontsize=22)
if penalty == 'berg':
ax.set_title('Berg entropy', fontsize=22)
ax.set_ylabel(r'$|| f_t - f^\star||_{\infty}$', fontsize=18)
plt.tight_layout()
plt.savefig(
os.path.join(path, f'plot_cv_error_{penalty}_{dataname}.pdf'))
plt.show()
解决方法
sudo apt-get install -y texlive texlive-latex-extra texlive-fonts-recommended dvipng cm-super