Note
Go to the end to download the full example code.
Ridge Line Plotting¶
Kernel density estimate plots stacked by time period to show distribution changes over time.
Best for: Visualizing seasonal variation, temporal evolution of distributions
import diive as dv
Load example data¶
df = dv.load_exampledata_parquet()
print(f"Loaded {len(df)} records from {df.index[0].date()} to {df.index[-1].date()}")
> Loaded .parquet file
/home/docs/checkouts/diive/checkouts/latest/diive/configs/exampledata/exampledat
a_PARQUET_CH-DAV_FP2022.5_2013-2022_ID20230206154316_30MIN.parquet (0.049
seconds).
Loaded 175296 records from 2013-01-01 to 2022-12-31
Weekly ridge line plot¶
Show air temperature distribution for each week. Ridge lines display kernel density estimates stacked vertically, making it easy to compare distribution shapes across time periods.
df_2019 = df.loc[(df.index.year >= 2019) & (df.index.year <= 2019)].copy()
series_weekly = df_2019['Tair_f'].copy()
# The chrome (here just the x-axis label) goes into a shared FormatStyle;
# the ridgeline-specific rendering toggles stay as direct plot() arguments.
style = dv.plotting.FormatStyle(
xlabel='Air temperature',
xunits='(°C)',
)
rp = dv.plotting.RidgeLinePlot(
series=series_weekly
)
rp.plot(
how='weekly',
fig_width=8,
fig_height=10,
shade_percentile=0.5,
show_mean_line=False,
format_style=style
)
print("\nPlotted weekly ridge lines for 2019")
print(f"Weekly distribution shapes reveal seasonal temperature patterns")

Plotted weekly ridge lines for 2019
Weekly distribution shapes reveal seasonal temperature patterns
Total running time of the script: (0 minutes 1.989 seconds)