【问题标题】:Underlining text/making bold: python: RuntimeError: Failed to process string with tex because latex could not be found下划线文本/加粗:python:RuntimeError:无法用tex处理字符串,因为找不到乳胶
【发布时间】:2020-10-02 06:29:19
【问题描述】:

我这里有以下代码:

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')

这给了我输出:

我想在这个图中添加文字:

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

这给了我输出:

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

我试过了:

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

但这给了我错误:

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

谁能帮帮我?

【问题讨论】:

  • 试试thisthis
  • 您的系统上是否安装了 Latex 可执行文件?
  • 在您的路径上可见吗?你能打开一个终端并编译一个乳胶文件吗? pycharm与此有什么关系?如果你正在使用它,我不会在普通终端中解决这个问题
  • @Caledonian26 我认为您的描述不正确。 matplotlib.org/tutorials/text/usetex.html?highlight=latex
  • @PaulH 在下面看到我的答案!

标签: python pandas string matplotlib annotations


【解决方案1】:

看来您不只是使用“普通”的 Matplotlib,而是使用嵌入在 Latex 中的它。因此,该错误与 Matplotlib 本身无关,而与 Latex 有关。 请看一下解决方案here

【讨论】:

  • 在下面查看我的答案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-07-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-17
  • 1970-01-01
  • 2019-03-19
相关资源
最近更新 更多