How to drag two 3D axes at once

In order to synchronize the rotation between two subplots in mplot3d you can connect the motion_notify_event to a function that reads the angles from rotated plot and applies it to the respective other plot. Here is an example from the gallery with the described functionality added. from mpl_toolkits.mplot3d import Axes3D from matplotlib import cm import … Read more

Plotting a 3d cube, a sphere and a vector

It is a little complicated, but you can draw all the objects by the following code: from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np from itertools import product, combinations fig = plt.figure() ax = fig.gca(projection=’3d’) ax.set_aspect(“equal”) # draw cube r = [-1, 1] for s, e in combinations(np.array(list(product(r, r, r))), 2): … Read more

How to make a 3D scatter plot

You can use matplotlib for this. matplotlib has a mplot3d module that will do exactly what you want. import matplotlib.pyplot as plt import random fig = plt.figure(figsize=(12, 12)) ax = fig.add_subplot(projection=’3d’) sequence_containing_x_vals = list(range(0, 100)) sequence_containing_y_vals = list(range(0, 100)) sequence_containing_z_vals = list(range(0, 100)) random.shuffle(sequence_containing_x_vals) random.shuffle(sequence_containing_y_vals) random.shuffle(sequence_containing_z_vals) ax.scatter(sequence_containing_x_vals, sequence_containing_y_vals, sequence_containing_z_vals) plt.show() The code above generates a … Read more

How to create 3D scatter animations

The scatter plot in 3D is a mpl_toolkits.mplot3d.art3d.Path3DCollection object. This provides an attribute _offsets3d which hosts a tuple (x,y,z) and can be used to update the scatter points’ coordinates. Therefore it may be beneficial not to create the whole plot on every iteration of the animation, but instead only update its points. The following is … 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