python - 如何更改图例标题 matplotlib 的字体粗细
问题描述
我正在尝试设置图例框标题的字体粗细(粗体或斜体),如下图所示。我的研究表明 plt.legend() 中的 title_fontsize 会改变字体大小。但是,我想不出改变字体粗细的方法。
plt.legend(
bbox_to_anchor=(1.04, 1),
loc="upper left",
borderaxespad=0.0,
title="Confidence \n Bands",
fancybox=True,
title_fontsize=18
)
解决方案
一个简单的方法是使用 Latex 表达式使其加粗。
plt.legend(
bbox_to_anchor=(1.04, 1),
loc="upper left",
borderaxespad=0.0,
title=r"$\bf{Confidence \\ Bands}$",
fancybox=True,
title_fontsize=18
)
推荐阅读
- python - PySpark DataFrames - 使用不同类型的列之间的比较进行过滤
- sorting - 如何按上次价格变化对产品进行排序?在 Magento 1.9
- solr - 在 Apache Solr 中插入文本文档
- deep-learning - 在 FasterRCNN 中,为什么短边尺寸为 600,最大尺寸为 1000?
- java - 在 Embedded Jetty 中与 Restful 一起部署网页
- angular - PrimeNg turbotable 过滤器不适用于行组
- mysql - 如何找到最接近的值并将其与记录合并?
- html - 调整大小时画布游戏不适合父 div
- javascript - 基于选项值选择问题的 Javascript 重定向
- java - JLabel 旁边的 JTextField