matplotlib.pyplot:设置轴单位的距离

时间:2019-05-30 09:22:17

标签: python matplotlib plot

import numpy as np
import matplotlib.pyplot as plt

x = [0,5,9,10,15]
y = [0,1,2,3,4]
plt.plot(x,y)
plt.xticks(np.arange(min(x), max(x)+1, 1))
plt.show()

显示 enter image description here

但是如果我将单位设置为0.5: plt.xticks(np.arange(min(x), max(x)+1, 0.5))个节目 enter image description here

x轴几乎不可读。

有没有一种方法可以为每个x轴单位设置距离,以便它可以自动扩展绘图(在x方向上)?

1 个答案:

答案 0 :(得分:0)

这有效:

import numpy as np
import matplotlib.pyplot as plt

x = [0,5,9,10,15]
y = [0,1,2,3,4]
plt.figure(figsize=(20,10))
plt.plot(x,y)
plt.xticks(np.arange(min(x), max(x)+1, 0.5))
plt.show()

按图的大小进行操作即可。玩,找到想要的尺寸/比率等。