bluemath_tk.core.plotting package
Submodules
bluemath_tk.core.plotting.base_plotting module
- class bluemath_tk.core.plotting.base_plotting.BasePlotting[source]
Bases:
ABC
Abstract base class for handling default plotting functionalities across the project.
- abstractmethod plot_line(x, y)[source]
Abstract method for plotting a line. Should be implemented by subclasses.
- class bluemath_tk.core.plotting.base_plotting.DefaultInteractivePlotting[source]
Bases:
BasePlotting
Concrete implementation of BasePlotting with interactive plotting behaviors.
- class bluemath_tk.core.plotting.base_plotting.DefaultStaticPlotting(template: str = 'default')[source]
Bases:
BasePlotting
Concrete implementation of BasePlotting with static plotting behaviors.
- plot_line(ax, **kwargs)[source]
Abstract method for plotting a line. Should be implemented by subclasses.
- plot_map(ax, **kwargs)[source]
Abstract method for plotting a map. Should be implemented by subclasses.
- plot_scatter(ax, **kwargs)[source]
Abstract method for plotting a scatter plot. Should be implemented by subclasses.
- templates = {'default': {'line': {'color': 'blue', 'line_style': '-'}, 'scatter': {'color': 'red', 'marker': 'o', 'size': 10}}}
bluemath_tk.core.plotting.colors module
- bluemath_tk.core.plotting.colors.GetFamsColors(num_fams: int) ndarray [source]
Get colors for wave families.
- Parameters:
num_fams (int) – Number of wave families.
- Returns:
Array of RGB colors for the specified number of wave families.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.colormap_bathy(topat: float, topag: float) ListedColormap [source]
Create custom colormap for bathymetry plot.
- Parameters:
topat (float) – Maximum topography value.
topag (float) – Minimum bathymetry value.
- Returns:
Custom colormap combining YlGnBu_r and turbid colormaps.
- Return type:
ListedColormap
- bluemath_tk.core.plotting.colors.colormap_spectra() ListedColormap [source]
Create custom colormap for spectra plots combining RdBu and rainbow colormaps.
- Returns:
Custom colormap combining RdBu and rainbow colormaps.
- Return type:
ListedColormap
- bluemath_tk.core.plotting.colors.colors_awt() ndarray [source]
Get colors for Annual Weather Types (6 categories).
- Returns:
Array of RGB colors for 6 AWT categories
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.colors_dwt(num_clusters: int) ndarray [source]
Get colors for Daily Weather Types.
- Parameters:
num_clusters (int) – Number of clusters to get colors for.
- Returns:
Array of RGB colors for the specified number of clusters.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.colors_fams_3() ndarray [source]
Get colors for 3 wave families.
- Returns:
Array of RGB colors for 3 wave families.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.colors_interp(num_clusters: int) ndarray [source]
Generate interpolated colors from Spectral colormap.
- Parameters:
num_clusters (int) – Number of clusters to generate colors for.
- Returns:
Array of RGB colors interpolated from Spectral colormap.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.colors_mjo() ndarray [source]
Get colors for MJO 25 categories.
- Returns:
Array of RGB colors for 25 MJO categories.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.get_cluster_colors(num_clusters: int) ndarray [source]
Get appropriate colors for clustering based on number of clusters.
- Parameters:
num_clusters (int) – Number of clusters to get colors for.
- Returns:
Array of RGB colors for the specified number of clusters.
- Return type:
np.ndarray
- bluemath_tk.core.plotting.colors.get_config_variables() Dict[str, Dict[str, Any]] [source]
Get configuration variables for different meteorological parameters.
- Returns:
Dictionary containing configuration for different variables: - geo500hpa: Geopotential height at 500hPa - mslp: Mean Sea Level Pressure - mslp_grad: MSLP gradient - sst: Sea Surface Temperature - other: Default configuration
- Return type:
Dict[str, Dict[str, Any]]
bluemath_tk.core.plotting.scatter module
- bluemath_tk.core.plotting.scatter.bias(pred: ndarray, tar: ndarray) float [source]
Calculate the bias between predicted and target values.
- Parameters:
pred (np.ndarray) – Array of predicted values.
tar (np.ndarray) – Array of target/actual values.
- Returns:
The bias value (mean difference between predictions and targets).
- Return type:
float
- bluemath_tk.core.plotting.scatter.density_scatter(x: ndarray, y: ndarray) Tuple[ndarray, ndarray, ndarray] [source]
Compute a density scatter for two arrays using gaussian KDE.
- Parameters:
x (np.ndarray) – X values for the scatter plot.
y (np.ndarray) – Y values for the scatter plot.
- Returns:
A tuple containing: - Sorted x values - Sorted y values - Density values corresponding to each point
- Return type:
Tuple[np.ndarray, np.ndarray, np.ndarray]
- bluemath_tk.core.plotting.scatter.plot_scatters_in_triangle(dataframes: List[DataFrame], data_colors: List[str] | None = None, **kwargs) Tuple[Figure, ndarray] [source]
Plot scatter plots of the dataframes with axes in a triangle arrangement.
- Parameters:
dataframes (List[pd.DataFrame]) – List of dataframes to plot. Each dataframe should contain the same columns.
data_colors (Optional[List[str]], optional) – List of colors for the dataframes. If None, uses default_colors.
**kwargs (dict, optional) – Additional keyword arguments for the scatter plot. These will be passed to matplotlib.pyplot.scatter. Common parameters include: - s : float, marker size - alpha : float, transparency - marker : str, marker style
- Returns:
A tuple containing: - Figure object - 2D array of Axes objects
- Return type:
Tuple[Figure, np.ndarray]
- Raises:
ValueError – If the variables in the first dataframe are not present in all other dataframes.
- bluemath_tk.core.plotting.scatter.rmse(pred: ndarray, tar: ndarray) float [source]
Calculate the Root Mean Square Error between predicted and target values.
- Parameters:
pred (np.ndarray) – Array of predicted values.
tar (np.ndarray) – Array of target/actual values.
- Returns:
The Root Mean Square Error value.
- Return type:
float
- bluemath_tk.core.plotting.scatter.si(pred: ndarray, tar: ndarray) float [source]
Calculate the Scatter Index between predicted and target values.
- Parameters:
pred (np.ndarray) – Array of predicted values.
tar (np.ndarray) – Array of target/actual values.
- Returns:
The Scatter Index value.
- Return type:
float
- bluemath_tk.core.plotting.scatter.validation_scatter(axs: Axes, x: ndarray, y: ndarray, xlabel: str, ylabel: str, title: str, cmap: str = 'rainbow') None [source]
Plot a density scatter and Q-Q plot for validation.
- Parameters:
axs (Axes) – Matplotlib axes to plot on.
x (np.ndarray) – X values for the scatter plot.
y (np.ndarray) – Y values for the scatter plot.
xlabel (str) – Label for the X-axis.
ylabel (str) – Label for the Y-axis.
title (str) – Title for the plot.
cmap (str, optional) – Colormap to use for the scatter plot. Default is “rainbow”.
bluemath_tk.core.plotting.utils module
- bluemath_tk.core.plotting.utils.create_cmap_from_colors(color_list: List[str], name: str = 'custom') LinearSegmentedColormap [source]
Create a colormap from a list of hex colors.
- Parameters:
color_list (List[str]) – List of hex color codes (e.g., [“#ff0000”, “#00ff00”])
name (str, optional) – Name for the colormap. Default is “custom”.
- Returns:
A colormap created from the provided colors.
- Return type:
colors.LinearSegmentedColormap
- bluemath_tk.core.plotting.utils.get_list_of_colors_for_colormap(cmap: str | Colormap, num_colors: int) list [source]
Get a list of colors from a colormap.
- Parameters:
cmap (Union[str, Colormap]) – The colormap to use.
num_colors (int) – The number of colors to generate.
- Returns:
A list of colors generated from the colormap.
- Return type:
list
- bluemath_tk.core.plotting.utils.join_colormaps(cmap1: str | List[str] | Colormap, cmap2: str | List[str] | Colormap, name: str = 'joined_cmap', range1: Tuple[float, float] = (0.0, 1.0), range2: Tuple[float, float] = (0.0, 1.0), value_range1: Tuple[float, float] = None, value_range2: Tuple[float, float] = None) Tuple[ListedColormap, BoundaryNorm] [source]
Join two colormaps into one, with value ranges specified for each.
- Parameters:
cmap1 (Union[str, List[str], Colormap]) – Input colormaps (name, list of hex codes, or Colormap object).
cmap2 (Union[str, List[str], Colormap]) – Input colormaps (name, list of hex codes, or Colormap object).
name (str) – Name of the output colormap.
range1 (Tuple[float, float]) – Portion of each colormap to use (from 0 to 1).
range2 (Tuple[float, float]) – Portion of each colormap to use (from 0 to 1).
value_range1 (Tuple[float, float]) – Value ranges in the data domain corresponding to each colormap.
value_range2 (Tuple[float, float]) – Value ranges in the data domain corresponding to each colormap.
- Returns:
ListedColormap – Merged colormap object.
BoundaryNorm – Normalization for mapping data to colors.