Book Image

Learning pandas - Second Edition

By : Michael Heydt
Book Image

Learning pandas - Second Edition

By: Michael Heydt

Overview of this book

You will learn how to use pandas to perform data analysis in Python. You will start with an overview of data analysis and iteratively progress from modeling data, to accessing data from remote sources, performing numeric and statistical analysis, through indexing and performing aggregate analysis, and finally to visualizing statistical data and applying pandas to finance. With the knowledge you gain from this book, you will quickly learn pandas and how it can empower you in the exciting world of data manipulation, analysis and science.
Table of Contents (16 chapters)

Manually rendering multiple plots in a single chart

It is often useful to contrast data by displaying multiple plots next to each other. We have seen that pandas does this automatically for several types of graphs. It is also possible to manually render multiple plots on the same canvas.

To render multiple subplots on a canvas with matplotlib, make multiple calls to plt.subplot2grid(). Each time pass the size of the grid the subplot is to be located on (shape=(height, width)) and the location on the grid of the upper-left location of the subplot (loc=(row, column)). The dimensions are in the overall number of columns and not pixels.

The return value from each call to plt.subplot2grid() is a different AxesSubplot object that can be used to specify the position of the rendering of the subplot.

The following code demonstrates this by creating a plot based on two rows and one column...