solarpy.plotting.irradiance_colormap_and_norm

solarpy.plotting.irradiance_colormap_and_norm#

solarpy.plotting.irradiance_colormap_and_norm(colormap='viridis', colormap_start=0.1, colormap_end=1, n_colormap=256, vmax=1000, solid_bands=None)#

Create a colormap and norm for visualizing solar irradiance data (W/m²).

The colormap is split into two regions:

  • Solid color bands for negative and near-zero values, where irradiance measurements are dominated by thermal offsets. The default bands (IRRADIANCE_COLOR_BANDS) encode data quality: unfeasible offsets [-100, -6), high negative offsets [-6, -2), acceptable negative offsets [-2, 0), and near-zero positive values [0, 2).

  • Continuous colormap for the physically meaningful range from the upper edge of the solid bands to vmax.

Parameters:
  • colormap (str or matplotlib.colors.Colormap, optional) – Colormap used for the continuous irradiance range. Any matplotlib colormap name or Colormap object is accepted. Default is 'viridis'.

  • colormap_start (float, optional) – Start point of the colormap in the range [0, 1]. Values above 0 skip the initial portion of the colormap, which can improve visibility on some backgrounds. Default is 0.1.

  • colormap_end (float, optional) – End point of the colormap in the range [0, 1]. Default is 1.

  • n_colormap (int, optional) – Number of discrete steps in the continuous colormap range. Higher values produce smoother color transitions. Default is 256.

  • vmax (float, optional) – Upper bound of the continuous colormap range [W/m²]. Values above vmax are clipped to the top color. Default is 1000.

  • solid_bands (list of tuple(float, float, str), optional) – List of (lower, upper, color) tuples defining the solid color bands. Each tuple specifies the lower bound (inclusive), upper bound (exclusive), and a matplotlib color string. Bands must be contiguous and sorted in ascending order. If None, defaults to IRRADIANCE_COLOR_BANDS.

Returns:

  • cmap (matplotlib.colors.ListedColormap) – Combined colormap with solid bands followed by the continuous range.

  • norm (matplotlib.colors.BoundaryNorm) – Norm that maps data values to the colormap boundaries.

Return type:

tuple[ListedColormap, BoundaryNorm]

Examples

Use as a drop-in colormap for an intraday heatmap:

>>> import solarpy
>>> import numpy as np
>>> import pandas as pd
>>> time = pd.date_range("2024-01-01", periods=365 * 1440, freq="1min")
>>> daily_cycle = np.sin(np.linspace(0, np.pi, 1440))
>>> values = np.tile(daily_cycle, 365) * 900 + np.random.randn(365 * 1440) * 5
>>> values -= 3  # introduce a small thermal offset
>>> cmap, norm = solarpy.plotting.irradiance_colormap_and_norm(vmax=1000)
>>> fig, ax = solarpy.plotting.plot_intraday_heatmap(
...     time=time,
...     values=values,
...     cmap=cmap,
...     norm=norm,
... )