gpt4 book ai didi

python - 二维核密度 e。在 python 中 - x 轴拥挤和缩小

转载 作者:太空宇宙 更新时间:2023-11-04 03:54:40 24 4
gpt4 key购买 nike

我有一个 x,y 点分布,我通过 scipy.stats.gaussian_kde 获得了 KDE。

kmsmins 都是一个浮点值列表,表示完成公里数所需的时间。

值分布在:

  • 分钟:[3.48996296296 - 317.678638298]
  • kms:[0.180707205317 - 8086.94362983]

在结果中我会得到一条又高又窄的线——y 值正常显示,但 x 轴非常窄且收缩(刻度线重叠)。有人可以指出如何拉伸(stretch) x 轴吗?

这是我生成绘图的代码:

xmin = min(mins)
xmax = max(mins)
ymin = min(kms)
ymax = max(kms)

X, Y = np.mgrid[xmin:xmax:1000j, ymin:ymax:100j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([mins, kms])
kernel = stats.gaussian_kde(values)
Z = np.reshape(kernel(positions).T, X.shape)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r, extent=[xmin, xmax, ymin, ymax])
ax.plot(mins, kms, 'k.', markersize=2)
ax.set_xlim([xmin, 200])
ax.set_ylim([ymin, ymax])

plt.show()

这是情节本身:

enter image description here

最佳答案

您可以通过以下方式将绘图的纵横比从 1:1 更改为自动

ax.axis('normal')

关于python - 二维核密度 e。在 python 中 - x 轴拥挤和缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19457140/

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