2

I have a x,y distribution of points for which I obtain the KDE through scipy.stats.gaussian_kde.

Both kms and mins are a list with float values representing the time needed to cover the amount of kilometres.

The values are distributed between:

  • mins: [3.48996296296 - 317.678638298]
  • kms: [0.180707205317 - 8086.94362983]

In the result I will get a high and narrow line -- the y values are shown normally, but the x-axis is very narrow and shrunken (the ticks are overlapping). Can somebody point out how the x axis can be more stretched?

Here is my code to generate the plot:

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

And here is the plot itself:

enter image description here

4

1 回答 1

2

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

ax.axis('normal')

于 2013-10-19T15:25:56.043 回答