【发布时间】:2022-01-15 19:06:08
【问题描述】:
我知道this question,它讨论了如何“全局”更改 matplotlib 中的字体大小。我的用例略有不同:我希望输出类似于
数组1 (元素数:100)
数组1 (元素数:250)
所以 MWE 应该是:
import numpy as np
from matplotlib import pyplot as plt
a = np.random.rand(100)
b = np.random.rand(250)
plt.hist(a, bins=100, label='Array 1 (number of elements: {})'.format(a.shape[0]))
plt.hist(b, bins=100, label='Array 2 (number of elements: {})'.format(b.shape[0]))
plt.legend()
plt.show()
plt.close()
如何在 matplotlib 中仅“本地”更改字体大小?
编辑:抱歉,如果输出看起来令人困惑,但小字体大小的部分不应该是上或下,它应该更小。
【问题讨论】:
-
使用带上标的乳胶语法
text $^\mathrm{small text}$。 -
@AndrasDeak 这对我不起作用,因为我使用字符串格式并且收到错误消息
unexpected '{' in field name。 -
你必须像往常一样转义大括号。
rf'text $^\mathrm{{{a.shape[0]}}}$'。一对大括号是字面大括号,第三个是格式。
标签: python numpy matplotlib font-size