Last updated: 08-07-2025 07:13
This is a demo site built using Quarto and Python. Check out
the full Substack post here.
Code
import seaborn as sns
import matplotlib.pyplot as plt
# Function for generating the Seaborn plot
def plot_stock_timeseries_seaborn(df):
"""
Creates a Seaborn line plot for all columns in the DataFrame.
Parameters:
df (pd.DataFrame): DataFrame with float columns and DatetimeIndex as index.
"""
# Set Seaborn theme
="whitegrid") # White grid background
sns.set_theme(style
# Initialize the figure
= plt.subplots(figsize=(8, 5))
fig, ax
# Add a line for each column
for col in df.columns:
=df, x=df.index, y=col, linewidth=2.5, label=col, ax=ax)
sns.lineplot(data
# Customize the plot
"Tech Stocks Indexed to 2023-01-01=100", fontsize=16, loc='left')
ax.set_title("", fontsize=12)
ax.set_xlabel("", fontsize=12)
ax.set_ylabel(=10, title_fontsize=12)
ax.legend(fontsize=True, linestyle="--", alpha=0.6)
ax.grid(visiblefor spine in ax.spines.values():
"none")
spine.set_color(
# Show the plot
plt.tight_layout()
plt.show()
# Generate the Seaborn plot
plot_stock_timeseries_seaborn(data_rebase)
Code
from datetime import datetime
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# Create a seaborn time series plot with a white grid theme using an ax object
="whitegrid") # White grid background
sns.set_theme(style= plt.subplots(figsize=(8, 5))
fig, ax =df, x=df.index, y="Ggdpnow", linewidth=2.5, color="blue", ax=ax)
sns.lineplot(data
# Customize the plot
"US GDP Nowcast (Seasonally Adjusted Annual Rate)", fontsize=16, loc='left')
ax.set_title("", fontsize=12)
ax.set_xlabel("", fontsize=12)
ax.set_ylabel(=True, linestyle="--", alpha=0.6)
ax.grid(visible"left"].set_color("none")
ax.spines["bottom"].set_color("none")
ax.spines["right"].set_color("none")
ax.spines["top"].set_color("none")
ax.spines[# Add a horizontal line at y=0
0, color="gray", linestyle="--", linewidth=1.5, alpha=0.8)
ax.axhline(
# Show the plot
plt.tight_layout() plt.show()