问题描述
这个警告是什么意思?我怎样才能摆脱这个?
Support for setting the 'text.latex.preamble' or 'pgf.preamble' rcParam to a list of strings is deprecated since 3.3 and will be removed two minor releases later; set it to a single string instead.
plt.rcParams['text.latex.preamble'] = [r"\usepackage{bm}",[r"\usepackage{amsmath}"]
代码:
import matplotlib.pyplot as plt
plt.rcParams['text.latex.preamble'] = [r"\usepackage{bm}"],[r"\usepackage{amsmath}"]
params = {'text.usetex' : True,'font.size' : 28,'font.family' : 'lmodern',}
plt.rcParams.update(params)
解决方法
根据文档 https://matplotlib.org/3.3.0/api/prev_api_changes/api_changes_3.3.0/deprecations.html#setting-rcparams-text-latex-preamble-default-or-rcparams-pdf-preamble-to-non-strings,将 rcParams['text.latex.preamble']
设置为字符串列表不再是正确的方法。
要解决此问题,您应该更换
plt.rcParams['text.latex.preamble'] = [r"\usepackage{bm}"],[r"\usepackage{amsmath}"]
成为
plt.rcParams['text.latex.preamble'] = r"\usepackage{bm} \usepackage{amsmath}"