Take a look at all the available Matplotlib Visualization styles in one-go, for use as a template when needed!
Published on March 03, 2022 by Vimal Octavius PJ
Matplotlib Visualization Aesthetics Time Series Plot
221 min READ
import matplotlib.pyplot as plt
%matplotlib inline
import warnings
warnings.filterwarnings('ignore')
import numpy as np
Viewing the available styles:
styles = plt.style.available[:]
n = 1
for i in styles:
print(n, i)
n+=1
1 Solarize_Light2 2 _classic_test_patch 3 bmh 4 classic 5 dark_background 6 fast 7 fivethirtyeight 8 ggplot 9 grayscale 10 seaborn 11 seaborn-bright 12 seaborn-colorblind 13 seaborn-dark 14 seaborn-dark-palette 15 seaborn-darkgrid 16 seaborn-deep 17 seaborn-muted 18 seaborn-notebook 19 seaborn-paper 20 seaborn-pastel 21 seaborn-poster 22 seaborn-talk 23 seaborn-ticks 24 seaborn-white 25 seaborn-whitegrid 26 tableau-colorblind10
Plotting the same graph in each style:
series = np.random.randn(50) #Generate random time series data
def trend_graph():
fig = plt.figure(figsize=(13,5))
ax = fig.add_subplot(111)
plt.grid()
ax.plot(series)
ax.set_title('A Time Series Plot', fontsize=18, fontweight='bold')
ax.set_xlabel('Day', fontsize=15)
ax.set_ylabel('Amount', fontsize=15)
ax.axis([0,50, -5, 5])
for s in styles:
with plt.style.context(s):
trend_graph()
I always come back to this code, to select the style I could apply easily to any plot, without much change to the code. All I have to do is:
Here goes the code:
series = np.random.randn(50) #Generate random time series data
def trend_graph():
fig = plt.figure(figsize=(13,5))
ax = fig.add_subplot(111)
plt.grid()
ax.plot(series)
ax.set_title('A Time Series Plot', fontsize=18, fontweight='bold')
ax.set_xlabel('Day', fontsize=15)
ax.set_ylabel('Amount', fontsize=15)
ax.axis([0,50, -5, 5])
with plt.style.context('grayscale'):
trend_graph()
If I need a style with a dark background, I have this: (Note that there is no change in the code except the line to display the style "with plt.style.context('dark_background')"
series = np.random.randn(50) #Generate random time series data
def trend_graph():
fig = plt.figure(figsize=(13,5))
ax = fig.add_subplot(111)
plt.grid()
ax.plot(series)
ax.set_title('A Time Series Plot', fontsize=18, fontweight='bold')
ax.set_xlabel('Day', fontsize=15)
ax.set_ylabel('Amount', fontsize=15)
ax.axis([0,50, -5, 5])
with plt.style.context('dark_background'):
trend_graph()