使用maplotlib或seaborn画图时,对x,y轴或title字体的设置。

基本框架如下,以标题字体为例

import matplotlib.pyplot as plt
import seaborn as sns

sns.boxplot(data)
plt.xlabel('')
plt.ylabel('')
plt.title('Fabc',fontsize=25,fontweight='bold',fontfamily='Times New Roman')

fontsize设置字体大小

fontweight设置字体加粗

fontfamily设置字体

一、斜体

1.使用style='italic’,可以使整体变成斜体

plt.title('Fabc',style='italic',fontsize=25,fontweight='bold',fontfamily='Times New Roman')

优点:斜体后,字体保持一致

缺点:只能整体变斜体

2.使用\it

plt.title(r'F$\it{abc}$',fontsize=25,fontweight='bold',fontfamily='Times New Roman')

好处:可以部分斜体

坏处:斜体后字体不一致

二、上下角标

类似\it用^表示上标,_表示下标

plt.title(r'F$^{abc}$',fontsize=25,fontweight='bold',fontfamily='Times New Roman')
plt.title(r'F$_{abc}$',fontsize=25,fontweight='bold',fontfamily='Times New Roman')

结果如下

上下角标可以结合使用\regular{}来使字体一致,但斜体我没有尝试成功

plt.title(r'$\regular{F_{abc}}$',fontsize=25,fontweight='bold',fontfamily='Times New Roman')

参考:

(44条消息) Matplotlib绘图坐标轴上下标和部分字体格式设置_matplotlib 上标_asqddd的博客-CSDN博客

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐