Pandas Dataframe by Example: Plot Examples with Pyplot

Last updated:
Table of Contents

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

You need to have the matplotlib module installed for this!

Sample data for examples

sample-pandas-dataframe This is what our sample dataset looks like

You can plot data directly from your DataFrame using the plot() method:

Simplest possible scatter plot

# a scatter plot comparing num_children and num_pets
df.plot(kind='scatter',x='num_children',y='num_pets')

simple scatter plot based on pandas dataframe You can plot a scatter plot directly from dataframe columns using df.plot

Simplest possible line plot

# a simple line plot
df.plot(kind='line',x='name',y='age')

simple line plot By changing the 'kind' parameter to 'line', you get a line plot instead.

Save plot to file

TODO

Stacked bar plot with groupby data

TODO

References

  • A lot of other types of plot are available. See all of them here

Dialogue & Discussion