In [1]:
%load_ext watermark

In [2]:
%watermark -u -v -d -p matplotlib,numpy


Last updated: 16/08/2014 

CPython 3.4.1
IPython 2.0.0

matplotlib 1.3.1
numpy 1.8.2

[More info](http://nbviewer.ipython.org/github/rasbt/python_reference/blob/master/ipython_magic/watermark.ipynb) about the `%watermark` extension


In [3]:
%matplotlib inline

Special plots in matplotlib

Sections



Basic pie chart


In [5]:
from matplotlib import pyplot as plt
import numpy as np

plt.pie(
    (10,5),
    labels=('spam','ham'),
    shadow=True,
    colors=('yellowgreen', 'lightskyblue'),
    explode=(0,0.15), # space between slices 
    startangle=90,    # rotate conter-clockwise by 90 degrees
    autopct='%1.1f%%',# display fraction as percentage
    )
plt.legend(fancybox=True)
plt.axis('equal')     # plot pyplot as circle
plt.tight_layout()
plt.show()




Basic triangulation


In [5]:
from matplotlib import pyplot as plt
import matplotlib.tri as tri
import numpy as np

rand_data = np.random.randn(50, 2)

triangulation = tri.Triangulation(rand_data[:,0], rand_data[:,1])

plt.triplot(triangulation)

plt.show()




xkcd-style plots


In [7]:
import matplotlib.pyplot as plt

x = [1, 2, 3]

y_1 = [50, 60, 70]
y_2 = [20, 30, 40]

with plt.xkcd():

    plt.plot(x, y_1, marker='x')
    plt.plot(x, y_2, marker='^')

    plt.xlim([0, len(x)+1])
    plt.ylim([0, max(y_1+y_2) + 10])
    plt.xlabel('x-axis label')
    plt.ylabel('y-axis label')
    plt.title('Simple line plot')
    plt.legend(['sample 1', 'sample2'], loc='upper left')

    plt.show()



In [8]:
import numpy as np
import random
from matplotlib import pyplot as plt

data = np.random.normal(0, 20, 1000) 
bins = np.arange(-100, 100, 5) # fixed bin size

with plt.xkcd():
    plt.xlim([min(data)-5, max(data)+5])

    plt.hist(data, bins=bins, alpha=0.5)
    plt.title('Random Gaussian data (fixed bin size)')
    plt.xlabel('variable X (bin size = 5)')
    plt.ylabel('count')

    plt.show()



In [9]:
from matplotlib import pyplot as plt
import numpy as np

with plt.xkcd():
    X = np.random.random_integers(1,5,5) # 5 random integers within 1-5
    cols = ['b', 'g', 'r', 'y', 'm']
    plt.pie(X, colors=cols)
    plt.legend(X)

    plt.show()