Note
Go to the end to download the full example code.
HeatmapXYZ (Basic)¶
Heatmaps for pre-aggregated data: binned by two dimensions (x, y), colored by a third (z). Shows relationships between two variables through aggregated flux values.
Best for: Visualizing binned flux relationships (e.g., NEE binned by temperature and VPD)
import diive as dv
Load and aggregate data¶
Create a GridAggregator to bin data by two variables (temperature and VPD) and compute mean NEE for each bin. HeatmapXYZ requires pre-aggregated data.
df = dv.load_exampledata_parquet()
# Select a time period and remove missing values
df_clean = df.loc[df.index.year == 2022].copy()
df_clean = df_clean[['Tair_f', 'VPD_f', 'NEE_CUT_REF_f']].dropna()
print(f"Loaded {len(df_clean)} records for aggregation")
# Aggregate data into 2D bins (temperature x VPD)
q = dv.analysis.GridAggregator(
x=df_clean['Tair_f'], # Temperature on x-axis
y=df_clean['VPD_f'], # VPD on y-axis
z=df_clean['NEE_CUT_REF_f'], # NEE as color values
binning_type='quantiles', # Create quantile-based bins
n_bins=10, # 10 bins per dimension
min_n_vals_per_bin=5, # Min 5 values per bin
aggfunc='mean' # Average within bins
)
print(f"Created {q.df_agg_long.shape[0]} bins from gridaggregator")
> 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 17520 records for aggregation
Created 84 bins from gridaggregator
HeatmapXYZ from GridAggregator¶
Create heatmap directly from GridAggregator output using from_gridaggregator(). Automatically handles bin column naming and pre-aggregated data format.
hm = dv.plotting.HeatmapXYZ.from_gridaggregator(
q, # GridAggregator instance
x_col='Tair_f', # Original x series name
y_col='VPD_f', # Original y series name
z_col='NEE_CUT_REF_f' # Original z series name
)
# Chrome (title/fonts) lives in a FormatStyle; the colorbar (cmap/vmin/vmax/
# cb_*) and the value/grid overlays stay direct on plot() -- FormatStyle does
# not own the colorbar.
hm.plot(
ax=None, # Create new figure
format_style=dv.plotting.FormatStyle(title='NEE binned by Temperature and VPD', show_grid=True),
figsize=(10, 8), # Figure size
cmap='RdYlGn', # Colormap (red=low uptake, green=high)
vmin=-5, # Minimum color value (umol/m2/s)
vmax=5, # Maximum color value
cb_digits_after_comma=1, # Colorbar precision
show_values=True, # Overlay bin values
show_values_n_dec_places=1 # 1 decimal place for values
)
print("Plotted HeatmapXYZ with temperature x VPD bins")

Plotted HeatmapXYZ with temperature x VPD bins
HeatmapXYZ with custom styling¶
Create heatmap with custom colormap and suppress value overlays for cleaner appearance.
hm2 = dv.plotting.HeatmapXYZ.from_gridaggregator(
q,
x_col='Tair_f',
y_col='VPD_f',
z_col='NEE_CUT_REF_f'
)
hm2.plot(
ax=None,
format_style=dv.plotting.FormatStyle(title='NEE Response Surface (Continuous)'),
figsize=(10, 8),
cmap='viridis', # Alternative colormap
vmin=-5,
vmax=5,
show_values=False, # Don't show values
show_colormap=True # Show colorbar
)
print("Plotted HeatmapXYZ with continuous colormap")

Plotted HeatmapXYZ with continuous colormap
HeatmapXYZ - variability (std) instead of mean¶
Run GridAggregator with aggfunc=’std’ to see within-bin variability. Complements the mean plot: high std where the flux response is uncertain or noisy.
q_std = dv.analysis.GridAggregator(
x=df_clean['Tair_f'],
y=df_clean['VPD_f'],
z=df_clean['NEE_CUT_REF_f'],
binning_type='quantiles',
n_bins=10,
min_n_vals_per_bin=5,
aggfunc='std' # standard deviation within each bin
)
hm_std = dv.plotting.HeatmapXYZ.from_gridaggregator(
q_std,
x_col='Tair_f',
y_col='VPD_f',
z_col='NEE_CUT_REF_f'
)
hm_std.plot(
ax=None,
format_style=dv.plotting.FormatStyle(title='NEE within-bin variability (std)', show_grid=True),
figsize=(10, 8),
cmap='YlOrRd', # low std = yellow, high std = red
cb_digits_after_comma=1,
show_values=True,
show_values_n_dec_places=1
)
print("Plotted HeatmapXYZ with std aggregation")

Plotted HeatmapXYZ with std aggregation
Total running time of the script: (0 minutes 0.679 seconds)