如果附加了ylabel字体位置,如何在matplotlib中调整它们?

问题描述 投票:0回答:1

![enter image description here

这是我的情节。

我尝试旋转,但它仍然附着。

如何将它们拆下并正确展示?

但是,我还有 2 个 y 轴刻度标签。

如果调整的话,我想为总共 4 个 y 轴刻度标签制作相同的格式。

这是代码。

import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()

ax1.set_ylim([0, 0.7])

ax1 = ax1.twinx()

ax1.set_xticks([5, 15, 25, 35])
ax1.set_yticks([0.1156, 0.1904, 0.2062, 0.4879])

ax1.plot([5, 15, 25, 35], [0.1156, 0.1904, 0.2062, 0.4879], linewidth=2, color='black')
ax1.plot(40, 0.7)


ax1.set_yticklabels(['24', '40', '43', '103'], minor=False, fontsize=15, fontweight='bold')
python matplotlib
1个回答
0
投票

作为一个选项,您可以将

fontsize
减少到 10。

import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()
ax1.set_ylim([0, 0.7])
ax1 = ax1.twinx()
ax1.set_xticks([5, 15, 25, 35])
ax1.set_yticks([0.1156, 0.1904, 0.2062, 0.4879])
ax1.plot([5, 15, 25, 35], [0.1156, 0.1904, 0.2062, 0.4879], linewidth=2, color='black')
ax1.plot(40, 0.7)
ax1.set_yticklabels(['24', '40', '43', '103'], minor=False, fontsize=10, fontweight='bold')

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.