In [1]:
%load_ext watermark

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


Last updated: 07/10/2015 

CPython 3.4.3
IPython 3.2.0

matplotlib 1.4.3
numpy 1.9.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



Matplotlib Formatting III: What it takes to become a legend

I won't be a rock star. I will be a legend.

-- Freddie Mercury



Sections



Back to square one


In [6]:
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(10)

for i in range(1, 4):
    plt.plot(x, i * x**2, label='Group %d' % i)

plt.legend(loc='best')
plt.show()




Let's get fancy


In [7]:
x = np.arange(10)

for i in range(1, 4):
    plt.plot(x, i * x**2, label='Group %d' % i)

plt.legend(loc='best', fancybox=True, shadow=True)
plt.show()




Thinking outside the box


In [8]:
fig = plt.figure()
ax = plt.subplot(111)

x = np.arange(10)

for i in range(1, 4):
    ax.plot(x, i * x**2, label='Group %d' % i)

ax.legend(loc='upper center', 
          bbox_to_anchor=(0.5,  # horizontal
                          1.15),# vertical 
          ncol=3, fancybox=True)
plt.show()



In [22]:
fig = plt.figure()
ax = plt.subplot(111)

x = np.arange(10)

for i in range(1, 4):
    ax.plot(x, i * x**2, label='Group %d' % i)

ax.legend(loc='upper center', 
          bbox_to_anchor=(1.15, 1.02),
          ncol=1, fancybox=True)
plt.show()




I love when things are transparent, free and clear


In [27]:
x = np.arange(10)

for i in range(1, 4):
    plt.plot(x, i * x**2, label='Group %d' % i)

plt.legend(loc='upper right', framealpha=0.1)
plt.show()




Markers -- All good things come in threes!


In [32]:
from itertools import cycle
x = np.arange(10)

colors = ['blue', 'red', 'green']
color_gen = cycle(colors)

for i in range(1, 4):
    plt.scatter(x, i * x**2, label='Group %d' % i, color=next(color_gen))

plt.legend(loc='upper left')
plt.show()



In [35]:
from itertools import cycle
x = np.arange(10)

colors = ['blue', 'red', 'green']
color_gen = cycle(colors)

for i in range(1, 4):
    plt.scatter(x, i * x**2, label='Group %d' % i, color=next(color_gen))

plt.legend(loc='upper left', scatterpoints=1)
plt.show()



In [37]:
from itertools import cycle
x = np.arange(10)

colors = ['blue', 'red', 'green']
color_gen = cycle(colors)

for i in range(1, 4):
    plt.plot(x, i * x**2, label='Group %d' % i, marker='o')

plt.legend(loc='upper left')
plt.show()



In [38]:
from itertools import cycle
x = np.arange(10)

colors = ['blue', 'red', 'green']
color_gen = cycle(colors)

for i in range(1, 4):
    plt.plot(x, i * x**2, label='Group %d' % i, marker='o')

plt.legend(loc='upper left', numpoints=1)
plt.show()



In [ ]: