monet.plots
Functions
|
Save figure and add logo. |
|
Create a spatial scatter plot showing the bias (difference) between two columns in a DataFrame. |
- monet.plots.cmap_discretize(cmap, N)
Return a discrete colormap from a continuous colormap.
Creates a new colormap by discretizing an existing continuous colormap into N distinct colors while preserving the color transitions.
- Parameters:
cmap (str or matplotlib.colors.Colormap) – Colormap instance or registered colormap name to discretize. Example: cm.jet, ‘viridis’, etc.
N (int) – Number of discrete colors to use in the new colormap.
- Returns:
A new colormap object with N discrete colors based on the input colormap. The name will be the original colormap name with “_N” appended.
- Return type:
Examples
>>> from numpy import arange >>> from numpy.ma import resize >>> from matplotlib.pyplot import imshow >>> from matplotlib.cm import jet >>> x = resize(arange(100), (5, 100)) >>> djet = cmap_discretize(jet, 5) >>> imshow(x, cmap=djet)
- monet.plots.colorbar_index(ncolors, cmap, minval=None, maxval=None, dtype='int', basemap=None)
Create a colorbar with discrete colors and custom tick labels.
- Parameters:
ncolors (int) – Number of discrete colors to use in the colorbar.
cmap (str or matplotlib.colors.Colormap) – Colormap to discretize and use for the colorbar.
minval (float, optional) – Minimum value for the colorbar tick labels. If None and maxval is None, tick labels will range from 0 to ncolors. If None and maxval is provided, tick labels will range from 0 to maxval.
maxval (float, optional) – Maximum value for the colorbar tick labels. If None, tick labels will range from 0 or minval to ncolors.
dtype (str or type, default “int”) – Data type for tick label values (e.g., “int”, “float”).
basemap (matplotlib.mpl_toolkits.basemap.Basemap, optional) – Basemap instance to attach the colorbar to. If None, uses plt.colorbar.
- Returns:
(colorbar, discretized_cmap) where: - colorbar is the matplotlib.colorbar.Colorbar instance - discretized_cmap is the discretized colormap
- Return type:
- monet.plots.kdeplot(df, title=None, label=None, ax=None, **kwargs)
Create a kernel density estimate plot.
- Parameters:
df (pandas.Series or array-like) – Data to plot the distribution of.
title (str, optional) – Title for the plot.
label (str, optional) – Label for the plotted line (for legend).
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates a new figure and axes.
**kwargs – Additional arguments passed to seaborn’s kdeplot. Common options include ‘shade’, ‘bw’, and ‘color’.
- Returns:
The axes containing the plot.
- Return type:
- monet.plots.make_spatial_contours(modelvar, gridobj, date, m, dpi=None, savename='', discrete=True, ncolors=None, dtype='int', **kwargs)
Create a contour plot on a map with optional discrete colorbar.
- Parameters:
modelvar (numpy.ndarray) – 2D model variable array to contour.
gridobj (object) – Object containing grid information with LAT and LON variables.
date (datetime.datetime) – Date/time for the plot title.
m (mpl_toolkits.basemap.Basemap) – Basemap instance for mapping.
dpi (int, optional) – Dots per inch for the figure if saving.
savename (str, default “”) – If provided, save the figure to this path with date appended.
discrete (bool, default True) – If True, use a discrete colorbar instead of a continuous one.
ncolors (int, optional) – Number of discrete colors when using discrete colorbar.
dtype (str, default “int”) – Data type for colorbar tick labels.
**kwargs – Additional arguments to pass to contourf. Must include ‘cmap’ and ‘levels’.
- Returns:
The colorbar instance.
- Return type:
- monet.plots.make_spatial_plot(modelvar, m, dpi=None, plotargs={}, ncolors=15, discrete=False)
Create a basic spatial plot using imshow.
- Parameters:
modelvar (numpy.ndarray) – 2D model variable array to plot.
m (mpl_toolkits.basemap.Basemap) – Basemap instance for mapping.
dpi (int, optional) – Dots per inch for the figure. Higher values increase resolution.
plotargs (dict, default {}) – Additional arguments to pass to imshow. Common options include ‘cmap’, ‘vmin’, ‘vmax’, and ‘alpha’.
ncolors (int, default 15) – Number of discrete colors when using discrete colorbar.
discrete (bool, default False) – If True, use a discrete colorbar instead of a continuous one.
- Returns:
(figure, axes, colorbar, colormap, vmin, vmax) - figure: matplotlib Figure instance - axes: matplotlib Axes instance - colorbar: matplotlib Colorbar instance - colormap: matplotlib Colormap instance - vmin, vmax: minimum and maximum values for the colormap
- Return type:
- monet.plots.normval(vmin, vmax, cmap)
Create a BoundaryNorm for discrete colormaps with specific bounds.
- Parameters:
vmin (float) – Minimum value for the colormap.
vmax (float) – Maximum value for the colormap.
cmap (matplotlib.colors.Colormap) – The colormap to create bounds for.
- Returns:
A boundary norm with evenly spaced bounds from vmin to vmax in steps of 5.0.
- Return type:
- monet.plots.savefig(fname, *, loc=1, decorate=True, logo=None, logo_height=None, **kwargs)
Save figure and add logo.
- Parameters:
fname (str) – Output file name or path. Passed to
plt.savefig. Must include desired file extension (.jpgor.png).loc (int) – The location for the logo.
1 – bottom left (default)
2 – bottom right
3 – top right
4 – top left
decorate (bool, default: True) – Whether to add the logo.
logo (str, optional) – Path to the logo to be used. If not provided, the MONET logo is used.
logo_height (float or int, optional) – Desired logo height in pixels. If not provided, the original logo image dimensions are used. Modify to scale the logo.
**kwargs (dict) – Passed to the
plt.savefigfunction.
- Return type:
None
- monet.plots.scatter(df, x=None, y=None, title=None, label=None, ax=None, **kwargs)
Create a scatter plot with regression line.
- Parameters:
df (pandas.DataFrame) – DataFrame containing the data to plot.
x (str, optional) – Column name for x-axis values.
y (str, optional) – Column name for y-axis values.
title (str, optional) – Title for the plot.
label (str, optional) – Label for the plot (for legend).
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates a new figure and axes.
**kwargs – Additional arguments passed to seaborn’s regplot. Common options include ‘scatter_kws’, ‘line_kws’, and ‘ci’.
- Returns:
The axes containing the plot.
- Return type:
- monet.plots.sp_scatter_bias(df, col1=None, col2=None, ax=None, outline=False, tight=True, global_map=True, map_kwargs={}, cbar_kwargs={}, val_max=None, val_min=None, **kwargs)
Create a spatial scatter plot showing the bias (difference) between two columns in a DataFrame.
- Parameters:
df (pandas.DataFrame) – DataFrame containing latitude, longitude, and data columns to compare.
col1 (str) – Name of the first column (reference value).
col2 (str) – Name of the second column (comparison value).
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates a new map using draw_map.
outline (bool, default False) – Whether to show the map outline.
tight (bool, default True) – Whether to apply tight_layout to the figure.
global_map (bool, default True) – Whether to set global map boundaries (-180 to 180 longitude, -90 to 90 latitude).
map_kwargs (dict, default {}) – Keyword arguments passed to draw_map if creating a new map.
cbar_kwargs (dict, default {}) – Keyword arguments for colorbar customization.
val_max (float, optional) – Maximum value for color scaling. If None, uses 95th percentile of absolute differences.
val_min (float, optional) – Minimum value for color scaling (not currently used).
**kwargs (dict) – Additional keyword arguments passed to DataFrame.plot.scatter.
- Returns:
The axes object containing the plot.
- Return type:
Notes
The point size is scaled by the magnitude of the difference between col2 and col1, making larger differences more visually prominent. Differences are capped at 300 units for display purposes.
- monet.plots.spatial(modelvar, **kwargs)
Create a simple spatial plot from an xarray object.
A convenience wrapper for xarray’s plot method with consistent styling.
- Parameters:
modelvar (xarray.DataArray) – The data to plot spatially.
**kwargs – Additional keyword arguments passed to xarray’s plot method. If ‘ax’ is not provided, a new figure and axes will be created.
- Returns:
The axes containing the plot.
- Return type:
- monet.plots.spatial_bias_scatter(df, m, date, vmin=None, vmax=None, savename='', ncolors=15, fact=1.5, cmap='RdBu_r')
Create a scatter plot showing bias between model and observations on a map.
- Parameters:
df (pandas.DataFrame) – DataFrame containing ‘latitude’, ‘longitude’, ‘CMAQ’, and ‘Obs’ columns.
m (mpl_toolkits.basemap.Basemap) – Basemap instance for mapping.
date (str or datetime.datetime) – Date to filter the DataFrame. Only entries matching this date will be plotted.
vmin (float, optional) – Minimum value for colorscale. If None, automatically determined.
vmax (float, optional) – Maximum value for colorscale. If None, automatically determined.
savename (str, default “”) – If provided, save the figure to this path with date appended.
ncolors (int, default 15) – Number of discrete colors for the colorbar.
fact (float, default 1.5) – Scaling factor for point sizes.
cmap (str or matplotlib.colors.Colormap, default “RdBu_r”) – Colormap to use for bias values.
- Returns:
(figure, axes, colorbar) containing the matplotlib objects.
- Return type:
Notes
The scatter points are colored by the difference (CMAQ - Obs) and sized by the absolute magnitude of this difference, making larger biases more visible.
- monet.plots.taylordiagram(df, marker='o', col1='obs', col2='model', label1='OBS', label2='MODEL', scale=1.5, addon=False, dia=None)
- No-index:
Create a DataFrame-based Taylor diagram using the TaylorDiagram class.
A convenience wrapper for easily creating Taylor diagrams from DataFrames. For the main Taylor diagram implementation, see
monet.plots.taylordiagram.- Parameters:
df (pandas.DataFrame) – DataFrame containing observation and model data
marker (str, default “o”) – Marker style for plotting model points
col1 (str, default “obs”) – Column name for observations
col2 (str, default “model”) – Column name for model predictions
label1 (str, default “OBS”) – Label for observations in legend
label2 (str, default “MODEL”) – Label for model in legend
scale (float, default 1.5) – Scale factor for diagram
addon (bool, default False) – If True, add to existing diagram; if False, create new
dia (TaylorDiagram, optional) – Existing diagram to add to if addon=True
- Returns:
The Taylor diagram instance
- Return type:
TaylorDiagram
- monet.plots.timeseries(df, x='time', y='obs', ax=None, plotargs={}, fillargs={'alpha': 0.2}, title='', ylabel=None, label=None)
Create a timeseries plot with shaded error bounds.
- Parameters:
df (pandas.DataFrame) – DataFrame containing the data to plot.
x (str, default “time”) – Column name to use for the x-axis (time).
y (str, default “obs”) – Column name to use for the y-axis (values to plot).
ax (matplotlib.axes.Axes, optional) – Axes to plot on. If None, creates a new figure and axes.
plotargs (dict, default {}) – Additional arguments to pass to DataFrame.plot().
fillargs (dict, default {“alpha”: 0.2}) – Additional arguments to pass to fill_between for the error shading.
title (str, default “”) – Title for the plot.
ylabel (str, optional) – Y-axis label. If None, uses variable name and units from DataFrame.
label (str, optional) – Label for the plotted line (for legend). If None, uses y.
- Returns:
The axes containing the plot.
- Return type:
Notes
This function groups the data by time, plots the mean values, and adds shading for ±1 standard deviation around the mean.
- monet.plots.wind_barbs(ws, wdir, gridobj, m, **kwargs)
Create a barbs plot of wind on a map.
- Parameters:
ws (numpy.ndarray) – 2D array of wind speeds.
wdir (numpy.ndarray) – 2D array of wind directions (meteorological convention, degrees).
gridobj (object) – Object containing grid information with LAT and LON variables.
m (mpl_toolkits.basemap.Basemap) – Basemap instance for mapping.
**kwargs – Additional arguments to pass to barbs. Common options include ‘length’, ‘pivot’, and ‘barb_increments’.
- Return type:
None
- monet.plots.wind_quiver(ws, wdir, gridobj, m, **kwargs)
Create a quiver plot of wind vectors on a map.
- Parameters:
ws (numpy.ndarray) – 2D array of wind speeds.
wdir (numpy.ndarray) – 2D array of wind directions (meteorological convention, degrees).
gridobj (object) – Object containing grid information with LAT and LON variables.
m (mpl_toolkits.basemap.Basemap) – Basemap instance for mapping.
**kwargs – Additional arguments to pass to quiver. Common options include ‘scale’, ‘scale_units’, and ‘width’.
- Returns:
The quiver instance.
- Return type:
Modules
Colorbar helper functions |
|
Map utilities. |
|
plotting routines |
|
|