gpt4 book ai didi

python - matplotlib 数据点之间的间距相等

转载 作者:行者123 更新时间:2023-12-01 02:27:24 26 4
gpt4 key购买 nike

我正在尝试绘制一些数据,其中 x 轴显示数据点之间的等距间距。

代码:

#!/usr/bin/env python
from matplotlib import pyplot as plt

sizes = [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]
prices = [245, 312, 279, 308, 199, 219, 405, 324, 319, 255]

plt.xlim([1000, 2500])
plt.ylim([0, 500])
plt.xlabel("sizes")
plt.ylabel("prices")

plt.scatter(sizes, prices)
plt.show()

外观: enter image description here我想要它的外观:

https://www.kdnuggets.com/2017/04/simple-understand-gradient-descent-algorithm.html

因此每两个相邻点之间的距离相等。

最佳答案

所以,看来你的图表只是为了表示目的。 x 轴上的数字不需要在刻度上。要绘制此图,您必须创建一个实际上按比例缩放的 x 轴列表,只需将其标签替换为 sizes 列表的元素即可。以下代码展示了如何执行此操作

#!/usr/bin/env python
from matplotlib import pyplot as plt

sizes = [1400, 1600, 1700, 1875, 1100, 1550, 2350, 2450, 1425, 1700]
prices = [245, 312, 279, 308, 199, 219, 405, 324, 319, 255]

plt.ylim([0, 500])
plt.xlabel("sizes")
plt.ylabel("prices")

x = [a for a in range(len(sizes))]
plt.scatter(x,prices)
plt.xticks(x, sizes)
plt.show()

关于python - matplotlib 数据点之间的间距相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47240638/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com