3D curvefitting

To fit a curve onto a set of points, we can use ordinary least-squares regression. There is a solution page by MathWorks describing the process. As an example, let’s start with some random data: % some 3d points data = mvnrnd([0 0 0], [1 -0.5 0.8; -0.5 1.1 0; 0.8 0 1], 50); As @BasSwinckels … 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

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

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]