Further plot customization with Matplotlib
For very simple plots, the default layouts may suffice, but you will inevitably run into cases where you need to further tweak the generated visualization. To go beyond the out-of-the-box features in pandas, it is helpful to understand some Matplotlib terminology. In Matplotlib, the figure refers to the drawing area, and an axes or subplot is the region on that figure that you can draw upon. Be careful not to confuse an axes, which is an area for plotting data, with an axis, which refers to the X- or Y-axis.
How to do it
Let’s start with a pd.Series
of our book sales data and try to plot it three different ways on the same figure – once as a line chart, once as a bar chart, and once as a pie chart. To set up our drawing area, we will make a call to plt.subplots(nrows=1, ncols=3)
, essentially telling matplotlib how many rows and columns of visualizations we want in our drawing area. This will return a two-tuple containing...