Graphs
import pandas as pd
import mathplotlib.pyplot as plt
x = [x1, x2, x3, ...]
x_df = pd.DataFrame({'column_name',x})
CHOOSE A CODE FROM BELOW (Bar, Pie, Histogram etc)
plt.suptitle("Plot Title")
plt.xlabel("x-axis label")
plt.ylabel("y-axis label")
- Bar graph (raw data)
x_df.groupby(['column_name']).size.plot(kind='bar') - Pie Chart (raw data)
x_df.groupby(['column_name']).size.plot(kind='pie', autopct='%1.1f%%') - Bar graph (frequency table)
x_df.plot.bar(x='column_name',y='frequency') - Pie chart (frequency table)
x_df.set_index('column_name',inplace=True)
x_df.plot.pie(y='frequency')
- Side by Side Bar (frequency table)
x_df.set_index('column_name',inplace=True)
x_df.plot.bar()
- Histogram
freq,bins,patches = plt.hist(x,bins=5,ec='k',range=[min(x),max(x)+1])
plt.xticks(bins) # df['column_name']=x
- Scater Plot (x, y list given)
plt.scatter(x,y)
Adapted from Python for Introductory Statistics: Student's Lab Workbook, by Simon Aman (Truman College, City Colleges of Chicago), licensed under CC BY 4.0. Changes were made: reformatted as an accessible XYZ web edition with live in-browser code cells. License: CC-BY-4.0.