如何使用matplotlib更改y刻度?

时间:2020-03-24 21:57:35

标签: python matplotlib data-visualization

我有子图,我只想将一个图的y刻度从0.1更改为10,因此将每个y刻度乘以10。 我尝试使用set_yticks([0, 10, 20, ..])进行设置,但不知何故,所有数字都挤到了顶部。有什么办法吗?

enter image description here

1 个答案:

答案 0 :(得分:1)

您正在寻找matplotlib.axes.Axes.set_yticklabels,这会将刻度线留在原处,但会更改标签。用法示例:

import matplotlib.pyplot as plt
import numpy as np

fig, axs = plt.subplots(1, 2, figsize=(12,6))
axs[0].set_yticklabels(np.linspace(0, 6, len(axs[0].get_yticks())))
plt.show()

enter image description here