python - Matplotlib 刻度标签字体粗细仅限于几个选项

标签 python matplotlib

看下面的代码

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(0.0001, 30, 1000)
y = np.sin(x)/x

fig, ax = plt.subplots(1, 1)
ax.plot(x, y)
ax.tick_params(which="major", labelsize=14, width=1.3)

for label in ax.get_xticklabels():
    label.set_fontweight(550) # If change to 551, label will be bold-like

根据here ,参数可以是数值或字符串。不过,我测试了两者。看起来标签 fontweight 与 [0, 550] 中的 fontweight 参数相同,在 [551 , 1000] 范围内,它变成粗体。此外,semiboldbold 似乎具有相同的字体粗细。

我假设字体粗细是线性变化的,但显然事实并非如此。任何人都可以解释为什么会这样吗?

最佳答案

一般情况下,一种字体只有有限的几种字体粗细,如RegularMediumBold等。字体粗细为不是无限的。

数值与有限字体粗细之间存在对应关系。更多详情请参见here .

关于python - Matplotlib 刻度标签字体粗细仅限于几个选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54084806/

相关文章:

python - 为图形的所有子图关闭轴

python - AxesSubplot 没有属性 xticks

python - 在 mac 上导入 matplotlib 错误

python - 如何让 python matplotlib 刷新所有图形

python - 在 python shell 中执行 bash 的复杂查找命令

python - 将列表拆分为奇数条目和偶数条目的两个列表

python - 使用 Platypus (Python) 进行整数、多目标优化

python - 使用 Matplotlib 调整图形

python - tensorflow 的 session 运行张量列表的顺序是什么?

python - FFMPEG - 图像到视频。来自 RAM 的图像? (Python)