← 返回首页
3D Scatterplot

3D Scatterplot

The `mplot3D` toolkit of matplotlib allows to easily create 3D scatterplots. This post explains how to draw it by providing a reproducible code.

In order to create a 3d graph, you should set projection parameter with '3d' keyword. Note that most of the customisations presented in the Scatterplot section will work in 3D as well. The result can be a bit disappointing since each marker is represented as a dot, not as a sphere..

# libraries from mpl_toolkits.mplot3d import Axes3D import matplotlib.pyplot as plt import numpy as np import pandas as pd # Dataset df=pd.DataFrame({'X': range(1,101), 'Y': np.random.randn(100)*15+range(1,101), 'Z': (np.random.randn(100)*15+range(1,101))*2 }) # plot fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(df['X'], df['Y'], df['Z'], c='skyblue', s=60) plt.show()

Colors

Interactivity

Animation

Cheat sheets

Caveats

3D

Statistics

🚨 Grab the Data To Viz poster!


Do you know all the chart types? Do you know which one you should pick? I made a decision tree that answers those questions. You can download it for free!

    Get Poster