简体   繁体   English

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

[英]matplotlib.pyplot: set distance for axis units

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()

shows 节目 在此输入图像描述

But if I set unit to 0.5: plt.xticks(np.arange(min(x), max(x)+1, 0.5)) shows 但如果我将单位设置为0.5: plt.xticks(np.arange(min(x), max(x)+1, 0.5))显示 在此输入图像描述

x-axis is hardly readable. x轴难以读取。

Is there a way to set distance for every x-axis unit so it could extend the plot automatically (on x direction)? 有没有办法为每个x轴单位设置距离,以便它可以自动扩展绘图(在x方向上)?

This works: 这有效:

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()

Operating on size of the figure does the job. 根据图的大小进行操作可以完成工作。 Play with it, find your desired size/ratio etc. 玩它,找到你想要的尺寸/比例等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM