Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions plots/spectrogram-basic/implementations/python/seaborn.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
""" pyplots.ai
""" anyplot.ai
spectrogram-basic: Spectrogram Time-Frequency Heatmap
Library: seaborn 0.13.2 | Python 3.13.11
Quality: 91/100 | Created: 2025-12-31
Library: seaborn 0.13.2 | Python 3.13.13
Quality: 86/100 | Updated: 2026-05-15
"""

import os

import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
from scipy import signal


# Theme tokens
THEME = os.getenv("ANYPLOT_THEME", "light")
PAGE_BG = "#FAF8F1" if THEME == "light" else "#1A1A17"
ELEVATED_BG = "#FFFDF6" if THEME == "light" else "#242420"
INK = "#1A1A17" if THEME == "light" else "#F0EFE8"
INK_SOFT = "#4A4A44" if THEME == "light" else "#B8B7B0"

# Data - chirp signal with increasing frequency
np.random.seed(42)
sample_rate = 4000 # Hz
Expand All @@ -32,7 +41,8 @@
Sxx_dB = 10 * np.log10(Sxx + 1e-10)

# Create plot
fig, ax = plt.subplots(figsize=(16, 9))
fig, ax = plt.subplots(figsize=(16, 9), facecolor=PAGE_BG)
ax.set_facecolor(PAGE_BG)

# Flip data vertically so low frequencies are at bottom (standard convention)
Sxx_dB_flipped = np.flipud(Sxx_dB)
Expand All @@ -54,23 +64,28 @@
time_tick_positions = np.linspace(0, Sxx_dB.shape[1], 5)
time_tick_labels = [f"{t:.1f}" for t in np.linspace(0, duration, 5)]
ax.set_xticks(time_tick_positions)
ax.set_xticklabels(time_tick_labels, fontsize=16)
ax.set_xticklabels(time_tick_labels, fontsize=16, color=INK_SOFT)

# Calculate tick positions for frequency axis (low to high, bottom to top)
freq_tick_positions = np.linspace(0, Sxx_dB.shape[0], 5)
freq_tick_labels = [f"{int(f)}" for f in np.linspace(frequencies[0], frequencies[-1], 5)]
ax.set_yticks(freq_tick_positions)
ax.set_yticklabels(freq_tick_labels[::-1], fontsize=16)
ax.set_yticklabels(freq_tick_labels[::-1], fontsize=16, color=INK_SOFT)

# Labels and styling
ax.set_xlabel("Time (s)", fontsize=20)
ax.set_ylabel("Frequency (Hz)", fontsize=20)
ax.set_title("spectrogram-basic · seaborn · pyplots.ai", fontsize=24, pad=20)
ax.set_xlabel("Time (s)", fontsize=20, color=INK)
ax.set_ylabel("Frequency (Hz)", fontsize=20, color=INK)
ax.set_title("spectrogram-basic · seaborn · anyplot.ai", fontsize=24, color=INK, pad=20)

# Adjust colorbar label size
# Style the colorbar
cbar = ax.collections[0].colorbar
cbar.ax.tick_params(labelsize=14)
cbar.ax.tick_params(labelsize=14, colors=INK_SOFT)
cbar.ax.yaxis.label.set_size(18)
cbar.ax.yaxis.label.set_color(INK)

# Set spine colors
for spine in ax.spines.values():
spine.set_color(INK_SOFT)

plt.tight_layout()
plt.savefig("plot.png", dpi=300, bbox_inches="tight")
plt.savefig(f"plot-{THEME}.png", dpi=300, bbox_inches="tight", facecolor=PAGE_BG)
Loading
Loading