O.2. Plot - JulTob/Python GitHub Wiki

Matplotlib

import numpy as np
import matplotlib.pyplot as plt


plt.xlabel("x axis")
plt.ylabel("y axis")
plt.xscale('linear')

Line Plot

import matplotlib.pyplot as plt

fig = plt.figure()
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
fig.savefig("plot.png")


xvalues = range(1,30,2)
plt.plot(xvalues, [x**2 for x in xvalues], linestyle = '--', color = 'k', label = "x2")

Bar Plot

import pandas as pd
import matplotlib

df = pd.DataFrame({ 'sample':['foo','bar','qux'], 'score':[5,9,7]})
sum_df = df.groupby("sample").sum()
bar_chart = sum_df.plot(kind="bar")

fig = bar_chart.get_figure()
fig.savefig("plot.png")