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

2
  • 1
    If you can provide a link to your picture, I can edit it to your question for you. Commented Oct 18, 2013 at 18:59
  • many thanks, you saved me a great deal of explanation this way. :) link Commented Oct 18, 2013 at 23:13

1 Answer 1

2

You can change the aspect ratio of the plot from 1:1 to automatic via

ax.axis('normal')

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.