0

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!

astromax
  • 6,001
  • 10
  • 36
  • 47
  • maybe this is helping http://stackoverflow.com/questions/7965743/python-matplotlib-setting-aspect-ratio – Johnny Apr 23 '13 at 16:43
  • I haven't tried the whole subplot routine, yet. That's a good idea, although I don't know if it will work with a 3D scatter plot. – astromax Apr 23 '13 at 16:58
  • Okay, I've tried a few things on the page you linked and they were all about changing the aspect ratio of the window itself, not the actual plot axes. Is there a way to adjust the axis range for 3D scatter plots? I'm looking to plot -x to x for all three axes. – astromax Apr 23 '13 at 17:06
  • I also came across this: http://stackoverflow.com/questions/8130823/set-matplotlib-3d-plot-aspect-ratio But again, this only changes the aspect ratio of the window... – astromax Apr 23 '13 at 17:21

1 Answers1

1

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.

Community
  • 1
  • 1
astromax
  • 6,001
  • 10
  • 36
  • 47