import matplotlib as mpl
import pandas as pd
import random
import mplstyle
import mplstyle.styles.simple as simple_style
# Save the current style parameters to a variable
base_style = mplstyle.get()
# Create a random data frame
def rand_vect(n):
return reduce(lambda m, x: m + [ m[-1] + random.random() - 0.5 ], range(n), [ random.random() ])
df = pd.DataFrame([ rand_vect(10) for x in range(5) ]).T
# Shorthand function creating the plot
def plot_df():
df.plot(grid=True)
# What the plot looks like before applying additional styles
plot_df()
# Now let's see what it looks like with the "pastel" style
mplstyle.set(simple_style)
mplstyle.set({ "lines": { "markersize": 4, "markeredgewidth": 0, "marker": "o" }})
plot_df()
# Example of passing keyword argument to a style module
mplstyle.set(simple_style, palette=mpl.cm.Pastel1)
plot_df()
# We can also layer on additional style rules,
# using nested dictionaries or dot notation, or both.
mplstyle.set({
"figure.figsize": (10, 8),
"lines": {
"marker": "s",
"markeredgewidth": 0.5
}
})
plot_df()
# And revert back to our original style rules...
mplstyle.reset(base_style)
plot_df()