[英]In matplotlib, how do you display an axis on both sides of the figure?
[英]How do you include a bold symbol in the axis when exporting a pgf figure using matplotlib?
我無法將使用 matplotlib 制作的 plot 導出到 pgf。 如果軸 label 中沒有粗體符號,則沒有問題,但出現錯誤。
這是我的代碼:
import seaborn as sns
import numpy as np
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
mpl.use('pgf')
mpl.rcParams.update({
'pgf.texsystem': "pdflatex",
'font.family': 'serif',
'text.usetex': True,
'pgf.rcfonts': False,
'font.serif': ["Computer Modern Roman"],
})
mpl.rc('text.latex', preamble=r'\usepackage{bm}')
import matplotlib.font_manager
import matplotlib.pyplot as plt
f, ax = plt.subplots(figsize = (8,4))
sns.set_color_codes("colorblind")
b = sns.barplot(x=probs, y=words, color='b')
ax.set(xlabel = r'{Probability of word, $p(w|\boldsymbol{\pi}_{ML})$}',
ylabel = r'{Word, $w$}' )
b.set_yticklabels(labels=b.get_yticklabels(), va='center')
f.tight_layout()
plt.savefig('graph.pgf', format='pgf')
我得到的錯誤是:
LatexError: LaTeX process halted
! Undefined control sequence.
<argument> ...rd, \(\displaystyle p(w|\boldsymbol
{\pi }_{ML})\)}
<*> ...displaystyle p(w|\boldsymbol{\pi}_{ML})\)}}
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on texput.log.
我認為在我的序言中包含\usepackage{bm}
會繞過這個問題嗎?
任何幫助將不勝感激!
本周第二次......嘗試調試和搜索的時間讓我在 stackoverflow 上發布后立即找到了解決方案。
解決方案:
mpl.rcParams.update({
'pgf.texsystem': "pdflatex",
'font.family': 'serif',
'text.usetex': True,
'pgf.rcfonts': False,
"pgf.preamble": "\n".join([
r"\usepackage{bm}",
]),
'font.serif': ["Computer Modern Roman"],
'text.latex.preamble': pream,
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.