我正在使用基于某些值的颜色贴图创建散点图,我正在尝试将x_axis标签的一部分用于斜体(主要受到这篇文章的启发 - > https://stackoverflow.com/a/8384685/1093485)但我得到一个LaTeX错误我无法解释自己,如果有人能够解释这个块的问题,我将不胜感激?
此处重现问题所需的最少代码:
#! /usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc
X = [1257.422648,1298.449197,1339.475746,1419.475471,1455.52309,1460.50202,1485.533655]
Y = [21.84637515,18.19617016,22.29456694,5.228978612,3.888695726,12.36598466,4.201838517]
Z = [44.02797944,9.758071204,21.58997772,64.53887544,53.09630431,8.461254471,291.4311435]
# Enable LaTeX style
rc('text',usetex=True)
# Plot the data
fig=plt.figure()
fig.patch.set_facecolor('white')
ax=fig.add_subplot(111)
s = ax.scatter(X,Y,c=np.log(Z))
ax.set_xlabel(r'Analyte \textit{m/z}')
ax.xaxis.labelpad = 7.5
cb = plt.colorbar(mappable=s,ax=ax)
plt.show()
评论rc('text',usetex=True)
会导致情节显示,但显然没有斜体。整个回溯相当大,但似乎围绕这一部分(如果我正确阅读):
RuntimeError: LaTeX was not able to process the following string:
'$1450$'
任何人都有建议如何解决问题?