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 causempl_toolkits.mplot3d
for creating the 3d projectionnumpy
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 🤓).