I took a look at how this might be implemented. There would have to be some extra work to make the plots look right when experiencing changes in aspect. I first tried an implementation of just the plot box aspect ratio (pbaspect) as a member variable of the axes object. It will probably turn into a property so that I can link it with a daspect value. Also, the values should be normalized to 1, unless you want to see some interesting shrinkage/growth of your plot area.
Try my branch here: https://github.com/WeatherGod/matplotlib/tree/mplot3d/pbaspect
After building that branch, try the following script (shamelessly adapted from some Matlab help pages for pbaspect and daspect).
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
fig = plt.figure()
ax = fig.gca(projection=‘3d’)
x, y = np.mgrid[-2:2:.2, -2:2:.2]
z = x * np.exp(-x2 - y2)
ax.plot_surface(x, y, z, rstride=1, cstride=1)
ax.pbaspect = [1.0, 1.0, 0.25]
While this will squash the z-axis nicely, it does not force the z-ticks to be pruned, so it gets a little ugly. However, the axis ticks can be changed manually. Also, with some of my other changes coming soon, it should be possible for the Axes3D object to automatically adjust the spacing of the tick labels so that it is not impacted by the changes in aspect ratio in the perpendicular direction (i.e. - the x and y tick labels are closer to the axis due to the z-axis scaling).
Keep an eye on that branch as I work to improve this feature, and feel free to contribute to it as well!
On Thu, Jun 9, 2011 at 10:13 AM, Benjamin Root <ben.root@…1304…> wrote:
On Thu, Jun 9, 2011 at 6:25 AM, Richard Hofmeister <richard.hofmeister@…3106…> wrote:
Hello mplot3d specialists,
I would like to change the aspect ratio of the 3d axes similar to matlab’s functionality with daspect() or the ‘dataaspectratio’ property of 3d-axes.
In the end, the x-y-plane should be non-square due to different lengths (not range) of the x and y axis (i know that i can use the aspect property of the axes to set the x-z/y-z aspect ratio).
There is also the package “scitools”, which provides all the matlab-3d functions including daspect via a VTK-backend; that would be my next try.
For the simple 3d-plotting without fancy shading, i would like to stick to mplot3d:
Is it possible to change the axis lengths/aspect ratios independently?
Good question. I have never thought about such a feature for mplot3d. Looking back at the code, it does not appear to be feasible to do in its current state, as the code seems to assume that the 3d grid is a constructed from a unit cube. However, I will see if I can add aspect multipliers to the point calculation and get arbitrary aspects. Maybe I can get that feature added into the upcoming 1.1.0 release.