Interactive 3D Visualization using Matplotlib

NOTE : This lesson is still under construction...


Matplotlib has the advantage of being easy to set up. Almost anyone that is working in machine learning or data science will already have this installed. There are, however, several reasons why you should avoid using it to visualize point clouds interactively in 3D.

Firstly matplotlib is incredibly slow. It will likely crash your computer if you want to actually visualize all of the points in something like a LIDAR scan.

Secondly, it just doesnt produce very nice point cloud visualizations. If you are processing LIDAR point clouds for instance, it is unlikely you will be able to recognize anything in the scene when using matplotlib.

Mayavi has the disadvantage of being quite tricky to install, but does an amazingly good job at visualizing point cloud data. So i would encourage trying that if you can.


NOTE : This lesson is still under construction...

In order to prevent matplotlib from crashing your computer, it is recomended to only view a subset of the point cloud data. For instance, if you are visualizing LIDAR data, then you may only want to view one in every 25-100 points. Below is some sample code to get you started.

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

skip = 100   # Skip every n points

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
point_range = range(0, points.shape[0], skip) # skip points to prevent crash
ax.scatter(points[point_range, 0],   # x
           points[point_range, 1],   # y
           points[point_range, 2],   # z
           c=points[point_range, 2], # height data for color
ax.axis('scaled')  # {equal, scaled}

TODO: show images comparing the output of matplotlib vs mayavi.