plot_heatmap#

plot_heatmap(title, tstart, tend, data_draw, depth, path_save='.', name_save='figure', n_colors=100)[source]#

Plot a time–depth heatmap using pcolormesh with adaptive color normalization and automatic time axis formatting.

This function creates a 2D heatmap representing variations of a variable across time and depth. The color range is determined from percentiles (5th–95th) to minimize the impact of outliers, and the colorbar uses evenly spaced, human-readable tick marks. Time ticks are automatically adjusted to daily, monthly, or yearly intervals depending on the duration of the dataset. The output figure is saved as a PNG file with a random suffix for uniqueness.

Parameters:
  • title (str) – Title of the figure.

  • tstart (datetime.datetime) – Start time of the dataset.

  • tend (datetime.datetime) – End time of the dataset. Must be later than tstart.

  • data_draw (np.ndarray) – 2D array of data values to visualize, with shape (n_time, depth).

  • depth (np.ndarray) – 1D array of depth values (length must match data_draw.shape[1]).

  • path_save (str, optional) – Directory where the output image will be saved. Default is the current directory ".".

  • name_save (str, optional) – Base filename (without extension) used for saving the output image. Default is "figure".

  • n_colors (int, optional) – Number of discrete color bins used in the colormap. Must be ≥ 2. Default is 100.

Returns:

Full path to the saved PNG figure.

Return type:

str