Surface and 3d contour in matplotlib

Apparently it is a bug, if you try this import numpy as np from mpl_toolkits.mplot3d import axes3d import matplotlib.pyplot as plt fig = plt.figure() ax = fig.add_subplot(111, projection=”3d”) X, Y = np.mgrid[-1:1:30j, -1:1:30j] Z = np.sin(np.pi*X)*np.sin(np.pi*Y) ax.plot_surface(X, Y, Z, cmap=”autumn_r”, lw=0, rstride=1, cstride=1) ax.contour(X, Y, Z+1, 10, lw=3, colors=”k”, linestyles=”solid”) plt.show() And rotate around, you … Read more

Setting aspect ratio of 3D plot

Add following code before savefig: ax.auto_scale_xyz([0, 500], [0, 500], [0, 0.15]) If you want no square axis: edit the get_proj function inside site-packages\mpl_toolkits\mplot3d\axes3d.py: xmin, xmax = np.divide(self.get_xlim3d(), self.pbaspect[0]) ymin, ymax = np.divide(self.get_ylim3d(), self.pbaspect[1]) zmin, zmax = np.divide(self.get_zlim3d(), self.pbaspect[2]) then add one line to set pbaspect: ax = fig.gca(projection = ‘3d’) ax.pbaspect = [2.0, 0.6, 0.25]

How to increase the size of an axis (stretch) in a 3D Plot

The code example below provides a way to scale each axis relative to the others. However, to do so you need to modify the Axes3D.get_proj function. Below is an example based on the example provided by matplot lib: http://matplotlib.org/1.4.0/mpl_toolkits/mplot3d/tutorial.html#line-plots (There is a shorter version at the end of this answer) from mpl_toolkits.mplot3d.axes3d import Axes3D from … Read more

How to display a 3D plot of a 3D array isosurface with mplot3D or similar

Just to elaborate on my comment above, matplotlib’s 3D plotting really isn’t intended for something as complex as isosurfaces. It’s meant to produce nice, publication-quality vector output for really simple 3D plots. It can’t handle complex 3D polygons, so even if implemented marching cubes yourself to create the isosurface, it wouldn’t render it properly. However, … Read more