Вопрос

I'm trying to make a 3D scatter plot using matplotlib. The issue I'm running into is that the plot isn't using a 1:1 aspect ratio between all pairs of the axes. Would anyone know how to fix this?

My code looks something like this:

from matplotlib.pyplot import *
from mpl_toolkits.mplot3d import *

figure(1, figsize=(7,7))
ax = gca(projection='3d')
ax.scatter(FH[:,0],FH[:,1],FH[:,2],s=0.5)
show()

I've tried adding kwargs like "aspect=1" to various parts of the script (i.e. - scatter(), figure(), ax()) but nothing has really worked so far.

Any help would be appreciated!

Thanks!

Это было полезно?

Решение

Okay - I've solved my problem. I found it here:set matplotlib 3d plot aspect ratio? (in a post that I overlooked).

My question was really how to set the bounding box (or extent) of my plot rather than one of how to set aspect ratio. The hack is that if you know the extent of the bounding box you would like to use to plot your data, plot invisible points like so:

fig=figure(1, figsize=(7,7))
ax = fig.gca(projection='3d')
ax.scatter(FH[:,0],FH[:,1],FH[:,2],s=0.5)

# plotting white points
MAX = 3 # I wanted -3 to 3 in each direction
for direction in (-1, 1):
    for point in diag(direction * MAX * array([1,1,1])):
        ax.plot([point[0]], [point[1]], [point[2]], 'w')

show()

Hope this helps. It's a little strange to me that I wasn't able to find a function/kwarg like extent for my 3D scatter plot, but I guess it doesn't mean the mechanism isn't there somehow.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top