带下划线的文本/加粗字体:python:RuntimeError:由于找不到乳胶,无法使用tex处理字符串

时间:2020-06-12 12:26:07

标签: python pandas string matplotlib annotations

我在这里有以下代码:

import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import matplotlib.colors
from simple-colors import * 

fig, ax = plt.subplots(1, 2, figsize = (8, 8))
ax[0].set_title('Deaths from Cancer in Michigan, 2020',pad=13,fontweight='bold',color='navy')
ax[1].set_title('Deaths from COVID-19 in Michigan, 2020',pad=13,fontweight='bold',color='navy')
ax[0].set_ylabel('Number of cases',labelpad=6,color='brown')
ax[1].set_ylabel('Number of cases',labelpad=6,color='brown')
ax[0].set_xlabel('Month',labelpad=6,color='brown')
ax[1].set_xlabel('Month',labelpad=6,color='brown')
ax[0].plot(COVID19['month'], COVID19['Cases'], color='green', marker='o', linestyle='dashed',linewidth=2, markersize=12)
ax[1].plot(Deaths['month'], Deaths['Cases'], color='red', marker='o', linestyle='dashed',linewidth=2, markersize=12)
ax[0].tick_params(axis='x', labelsize=10,rotation=45)
ax[1].tick_params(axis='x', labelsize=10,rotation=45)
ax[0].tick_params(axis='y', labelsize=10)
ax[1].tick_params(axis='y', labelsize=10)
Deaths = Deaths['Cases'].reset_index()
Deaths = Deaths.drop(['index'],axis=1)
fig.subplots_adjust(bottom=0.2)
Correlation = Deaths['Cases'].corr(COVID19['Cases'],method='pearson')

这给了我输出:

enter image description here

我想在此图中添加文字:

fig.text(0.3,0.05,'Pearsons Correlation Coefficient is {}'.format(Correlation))

这给了我输出:

enter image description here

但是,我想将“皮尔逊相关系数”部分加粗并加下划线。

我尝试过:

fig.text(0.3,0.05,"Pearson's Correlation Coefficient is: " + r"$\bf\underline{" + str(Correlation) + "}$")

但这给了我错误:

RuntimeError:由于找不到乳胶,无法使用tex处理字符串

有人可以帮我吗?

1 个答案:

答案 0 :(得分:-1)

似乎您不仅在使用“普通” Matplotlib,而且还将其嵌入在Latex上使用。因此,该错误本身与Matplotlib不相关,而与Latex有关。 请查看解决方案here

相关问题