如何在 matplotlib 中以不等间隙缩放 x 轴

发布于 2025-01-13 07:23:16 字数 522 浏览 5 评论 0原文

我必须使用下表:

在此处输入链接描述

并使用此代码创建以下图表:

代码

plt.plot(new[201], label='201')
plt.genend()
plt.show()

图:

在此输入链接描述

如何缩放 x 轴使其间隙不相等?

例如,如果我在 Excel 中使用相同的数据,我会得到以下图表:

在此处输入链接描述

那么我该如何制作python 中的图表与 excel 中的图表一样吗?

I have to following table:

enter link description here

and I create the following graph with this code:

code:

plt.plot(new[201], label='201')
plt.genend()
plt.show()

graph:

enter link description here

how can I scale the x-axis NOT to be with equal gaps?

for example, if I use the same data in excel I get this graph:

enter link description here

so how can I make the graph in python to be like in excel ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埖埖迣鎅 2025-01-20 07:23:16

您似乎将数据作为字符串。 x 轴很可能被字符串值占据。您还没有提供数据,所以我不知道 new[201] 是什么样的。但是,我想您所需要的只是将其转换为浮动,例如:

new[201].astype(np.float)

当然,这是针对 numpy 数组的。如果您的数据具有不同的格式,请检查将其从字符串转换为浮点数的具体方法。

You seem to have your data as strings. Most likely the x-axis is occupied by string values. You have not provided the data, so I have no idea what new[201] looks like. However, I guess all you need is to cast it to float with something like:

new[201].astype(np.float)

Of course, this is for numpy array. In case your data have a different format, check the specific way to cast it from string to float.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文