Beyond data scientist: 3d plots in Python with examples

Yuchen Z.
6 min readJul 18, 2019

Python is known to be good for data visualization. There are many tools in Python enabling it to do so: matplotlib, pygal, Seaborn, Plotly, etc. Among these, matplotlib is probably the most widely used one. On one hand, it offers a lot more flexibility; on the other hand, it is also very low-level and may not the most straightforward to use. There are a lot of articles explaining how to do 2d plotting with matplotlib already. In this post, we will focus more on plotting in 3d.

You can simply read through this as it. But to get the most out of these examples here, it is recommended that you open up a notebook and try them out.

Get started

Here are some necessary dependencies we will need:

  • matplotlib.pyplot of cause
  • mpl_toolkits.mplot3d for creating the 3d projection
  • numpy for manipulating data

We add %matplotlib inline so that we can display the plots inline in the notebook. This saves us from having to call plt.show() all the time. Alternatively, you could also use %matplotlib notebook to enter interactive mode, which allows you to simply click and drag to change the viewpoint.

We also change the default plot size here using rcParams. There are many more configurations that you can play with if you are interested. Assuming you are using a Jupyter notebook, then the size 12.8, 9.6 is perfect (by some definition 🤓).

--

--

Responses (1)