警告:改为将其设置为单个字符串

问题描述

这个警告是什么意思?我怎样才能摆脱这个?

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}"

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...