我的代码如下:
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')
这给了我以下输出:
然后,我尝试对该图进行注释:
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0;0m'
fig.text(0.3,0.05, (color.BOLD + "Pearson's Correlation Coefficient is: " + color.END + str(Correlation)))
但是,我得到一个错误:RuntimeWarning:当前字体缺少Glyph 27。 font.set_text(s,0.0,flags=flags)
当我尝试以下方法时:
class color:
PURPLE = '\033[95m'
CYAN = '\033[96m'
DARKCYAN = '\033[36m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
END = '\033[0;0m'
print(color.BOLD + color.UNDERLINE + "Pearson's Correlation Coefficient is: " + color.END)
这给了我:
因此,我能够将文本加粗并在其下划下划线
但是,我无法在上面的命令上下文中执行此操作(使用此字符串注释图形)
谁能帮我一把吗
在这里安装MacTex包:https://www.tug.org/mactex/(我使用的是mac)
一旦我在我的计算机上安装了这个软件包,我就不需要更改python解释器上的任何设置了-我只是让它保持原样
然后使用以下命令:
这将在“皮尔逊相关系数为:”文本下方加下划线并加粗
在单词之间添加一个两边都有空格的“\”将在单词之间添加空格
相关问题 更多 >
编程相关推荐