繁体   English   中英

我如何格式化 x 轴,以便我可以使用 matplotlib 跳过值

[英]how can I format the x axis such that I can skip over values using matplotlib

我想格式化我的 xticks,这样就没有任何间隙,因为我目前在下面的 plot 中有任何间隙。 我只想拥有数据中 x 轴上的点。

我的 x 轴点在下面,这就是我想要的,并且:

[128, 132, 136, 140, 149, 153, 157, 161, 36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124]

我怎样才能定义我的格式化程序?

地块1

可能的解决方案如下:

# pip install matplotlib

import matplotlib.pyplot as plt

# set data
x = [36, 40, 44, 48, 52, 56, 60, 64, 100, 104, 108, 112, 116, 120, 124, 128, 132,  136,  140, 149,  153, 157, 161]
y = [15.25, 15, 15.1, 14.9, 14.25, 14.1, 14, 13.9, 13.8, 14.2, 14.75, 14.8, 15.4, 15.45, 15.5, 15.25, 15.6, 15.2, 15.3, 15.25, 15.5, 15.2, 15.25]

plt.figure(figsize=(15, 4), dpi=80)

plt.plot(x, y)
plt.xticks(x) # << HERE

plt.show()

在此处输入图像描述

暂无
暂无

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

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