In [15]:
%matplotlib inline
In [16]:
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Use the GGPLOT style.
plt.style.use('ggplot')
In [17]:
for style in plt.style.available:
print(style)
In [18]:
# Create our data and labels.
labels = ['Mystery', 'Sports', 'Science', 'Biography', 'History']
s = pd.Series([24, 15, 33, 18, 27], index=labels)
In [19]:
# Show our data as a table.
title = "Books Checked Out"
pd.DataFrame(s, columns=[title])
Out[19]:
In [20]:
# Show our data as a bar plot.
fig = plt.figure(figsize=(7,6))
ax = s.plot(kind='bar', rot=45)
result = ax.set_title(title)
In [35]:
# Show our data as a bar plot.
with plt.style.context('ggplot'):
fig = plt.figure(figsize=(7,6))
ax = s.plot(kind='barh')
result = ax.set_title(title)
In [39]:
# Make a pie chart.
with plt.style.context('ggplot'):
fig = plt.figure(figsize=(6,6))
ax = plt.pie(s, labels=labels, autopct="%0.f%%", shadow=True)
ax = plt.gca()
o = ax.set_title(title)
In [41]:
# Student height data.
counts = [
(3, 2),
(7, 4),
(5, 8),
(6, 3),
(4, 0),
]
labels = [43, 44, 45, 46, 47]
df = pd.DataFrame(counts, index=labels, columns=['Boys', 'Girls'])
In [42]:
# Show the data as a table.
df
Out[42]:
In [44]:
# Plot boys and girls heights together ...
with plt.style.context('fivethirtyeight'):
ax = df.plot(kind='bar', rot=0)
o = ax.set_title("Student Heights")
In [46]:
# ... separately ...
# Plot boys and girls heights together ...
with plt.style.context('ggplot'):
axes = df.plot(kind='bar', rot=0, subplots=True)
for ax in axes:
ax.legend().remove()
In [50]:
# ... and stacked.
# Plot boys and girls heights together ...
with plt.style.context('ggplot'):
ax = df.plot(kind='bar', rot=0, stacked=True)
o = ax.set_title("Student Heights")