Python Matplotlib/Seaborn Template for Multi Variable plot

Viewed 113

I got to know about a beautiful plot and I am reproducing it below. I would like to know the template used for this kind of plot.

enter image description here

1 Answers

It looks like there isn't seaborn template available, but you can use matplotlib subplots and annotations to generate a similar plot.

I think the general method would be to fill the area between all of the curves, and annotate the minimum and maximum values. Here is an example of what you can do using gaussian curves with different standard deviations to produce the middle subplot.

import pandas as pd
import numpy as np
from scipy.signal.windows import gaussian
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

## create some simple gaussian curves
x = pd.date_range("2020-01-01", "2020-12-31", freq="D")
y_curves = [gaussian(len(x), std=s) for s in [40,80,120,160]]
colors = ["OrangeRed","Orchid","PeachPuff","LightGoldenRodYellow"]

y_max = max([max(y) for y in y_curves])

## loop through pairs of curves, filling between them
for i, y in enumerate(y_curves):
    if i == 0:
        plt.fill_between(x,y,color=colors[i])
    elif i == 2:
        plt.plot(x, y, color="black", linewidth=0.5)
        plt.fill_between(x,y,y_curves[i-1],color=colors[i])

        ## annotate max value
        y_max = max(y)
        y_max_idx = y.tolist().index(max(y))
        x_max = x[y_max_idx] 
        plt.annotate(text="muggy: 100%", xy=(x_max, y_max-0.05))

    else:
        plt.fill_between(x,y,y_curves[i-1],color=colors[i])

# Set the locator
locator = mdates.MonthLocator()  # every month
# Specify the format - %b gives us Jan, Feb...
fmt = mdates.DateFormatter('%b')

X = plt.gca().xaxis
X.set_major_locator(locator)
# Specify formatter
X.set_major_formatter(fmt)

plt.xlim([x[0], x[-1]])
plt.ylim([0, 1])
plt.show()

enter image description here

Related