In [3]:
import mpl_styles
from matplotlib import pyplot as plt
import numpy as np
%pylab inline
In [4]:
# We define some x and y values
x1 = range(10)
x2 = np.random.rand(100)
y1 = np.random.randn(10)
y2 = np.random.rand(100)
mpl_styles
provide some decorators to decorate your matplotlib plots. Some styles are included, 'gg', 'gg2', 'probpro', 'pybo', 'r'.
'gg', 'probpro' and 'r' are adapted from matplotlibrc demo files developed by Ryan Dale.
'gg2' is adapted from matplotlibrc developed by Huy Nguyen.
'pybo' uses the pybonacci logo colors.
It is very easy to include your own style. Just define your rc params
in a dictionary and include them in a new decorator. Then make a 'Pull Request' to this repo. It would be nice to see a gallery of beatiful styles here.
Otherwise, if you don't want to share your beatiful matplotlib configuration you can use your own styles using my_style
decorator which accepts a dictionary with your rc params
.
To use a style you just have to create your function with your plot and decorate the function with the decorator you want to use. See some dummy examples below:
The 'gg' style:
In [5]:
@mpl_styles.gg_style
def ggplot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [6]:
ggplot()
The 'gg2' style
In [18]:
@mpl_styles.gg2_style
def gg2plot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [19]:
gg2plot()
The 'probpro' style
In [20]:
@mpl_styles.probpro_style
def ppplot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [21]:
ppplot()
The 'pybo' style
In [22]:
@mpl_styles.pybo_style
def pyboplot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [23]:
pyboplot()
The 'r' style
In [24]:
@mpl_styles.r_style
def rplot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [25]:
rplot()
Your own style using a dictionary of rc params
as an argument for the decorator
In [26]:
params = {'lines.linewidth':5, 'axes.facecolor': '999999'}
@mpl_styles.my_style(params)
def myplot():
plt.subplot(2,2,1)
plt.plot(x1,y1)
plt.plot(x1,y1-1)
plt.plot(x1,y1-2)
plt.plot(x1,y1-3)
plt.plot(x1,y1-4)
plt.subplot(2,2,2)
plt.scatter(x2, y2)
plt.subplot(2,2,3)
plt.bar(x1, y1)
In [27]:
myplot()
A plot using the default style of the IPython notebook
In [28]:
plt.plot(x1, y1)
Out[28]: