Subplots with super lables
fig, axs = plt.subplots(2,3, sharey=True, sharex=True, figsize=(12, 6))
# ravel() so that we have one-dimensioanl array to loop
axs = axs.ravel()
for i, j in enumerate(years):
x = np.log(df_cleaned.query("year == @j")["gdp_pcap"]).values
y = df_cleaned.query("year == @j")["life_expectancy"].values
axs[i].scatter(x,y, s=10)
axs[i].set_title(j, fontsize=10)
# Super lables / outer margin
fig.supxlabel('Log GDP per capita')
fig.supylabel('Life Expectancy')
from matplotlib.ticker import FuncFormatter
def TICK_Million_f(x, pos):
return "{0:.1f}M".format(x * 1e-6)
TICK_Million = FuncFormatter(TICK_Million_f)
fig, ax = plt.subplots()
ax.hist(euro_pnl[0], bins=100, alpha = 0.6, label = "No hedging");
ax.hist(euro_pnl[2], bins=100, alpha = 0.7, label = "With hedging (next of cost)");
ax.set_xlabel("Simulated P&L (million dollars)", fontsize=16)
ax.set_ylabel("Frequency", fontsize=16)
ax.set_title("Hedging Funding Cost with European Caplet - P&L Distribution", fontsize=18)
ax.xaxis.set_major_formatter(TICK_Million)
ax.legend()
Distribution Plot
with plt.style.context('seaborn'):
sns.displot(y)
Correlation Plot
fig, ax = plt.subplots(figsize=(12,8))
sns.heatmap(df.corr(), annot=True, ax = ax, cmap='YlGnBu')
plt.show()
Pair Plot
with plt.style.context('seaborn'):
sns.pairplot(df)