mplstyler StylesManager demo

In [21]:
from mplstyler import StylesManager

styles = StylesManager()
In [22]:
from pylab import *
In [23]:
x = linspace(0, 5, 10)
y1 = x ** 2
y2 = x ** 3

First use

Now we’ve got the classes for the data plotted, we can now plot the mean values (of the spectra). To get a style assignment for a given class we need to call .get_style_for_class() on the styles manager. This returns a useable style object that can output the keyword arguments needed to correctly style matplotlib plots.

In [24]:

s = styles.get_style_for_class('Series 1')
plot(x, y1, **s.kwargs)

s = styles.get_style_for_class('Series 2')
plot(x, y2, **s.kwargs)


Second use

Now we’ve called styles.get_style_for_class() with a class (group) name the returned style is permanantly assigned for that class. Any subsequent calls with the same name will return the same class

In [26]:
from collections import OrderedDict

l = OrderedDict()
s = styles.get_style_for_class('Series 1')
l['Series 1'] = bar(x, y1, **s.bar_kwargs)

s = styles.get_style_for_class('Series 3')
l['Series 3'] = bar(max(x)+x, y2, **s.bar_kwargs)

leg = legend(l.values(), l.keys(),

In [25]:
In [ ]:


Related posts

Get my latest Python projects, tips & tutorials direct to your Inbox.