NEDAS.utils.graphics module
- NEDAS.utils.graphics.get_cmap(cmap_name: str)[source]
Get colormap object based on the input name string.
- Parameters:
cmap_name (str) – The name of the color map. For cmocean colormaps, the name should be in the format ‘cmocean.<cmap_name>’
- Returns:
A colormap object corresponding to the given name.
- Return type:
Colormap
- Raises:
KeyError – If the colormap name is not found.
- NEDAS.utils.graphics.adjust_ax_size(ax, wfac=1.0, hfac=1.0, boff=0.0)[source]
Make plot axes a little smaller on right hand side to make room for colorbar.
Even for axes without colorbar in a multi-pane plot, it is still useful to call this function so that the axes will align with those with colorbars.
- Parameters:
ax (matplotlib.axes.Axes) – Matplotlib axes object.
wfac (float, optional) – Ratio to scale the width of the axes. Defaults to 1.
hfac (float, optional) – Ratio to scale the height of the axes. Defaults to 1.
boff (float, optional) – Bottom offset to leave room for labels. Defaults to 0.
- NEDAS.utils.graphics.add_colorbar(fig, ax, cmap, vmin, vmax, nlevels=10, fontsize=12, units=None)[source]
Add a colorbar to the right-hand side of an axes.
This function adds a colorbar to the provided axes, using the specified colormap and value range. The number of levels, font size, and unit label can be customized.
- Parameters:
fig (matplotlib.figure.Figure) – Matplotlib figure object.
ax (matplotlib.axes.Axes) – Matplotlib axes object.
cmap (matplotlib.colors.Colormap) – Colormap to use for the colorbar.
vmin (float) – Minimum value for the colorbar.
vmax (float) – Maximum value for the colorbar.
nlevels (int, optional) – Number of color levels. Defaults to 10.
fontsize (int, optional) – Font size for tick labels and unit label. Defaults to 12.
units (str, optional) – Unit label to display as the colorbar title. Defaults to None.
- Returns:
The created colorbar object.
- Return type:
matplotlib.colorbar.Colorbar
- NEDAS.utils.graphics.arrowhead_xy(x1, x2, y1, y2, hw, hl)[source]
Given a line segment from (x1,y1) to (x2,y2), return the segments that draw an arrow head (for plotting vectors).
- Parameters:
x1 (float) – X-coordinate of the start point of line segment.
x2 (float) – X-coordinate of the end point of line segment.
y1 (float) – Y-coordinate of the start point of line segment.
y2 (float) – Y-coordinate of the end point of line segment.
hw (float) – Width of the arrow head.
hl (float) – Length of the arrow head.
- Returns:
X-coordinates of the additional line segments forming the arrowhead. list: Y-coordinates of the additional line segments forming the arrowhead.
- Return type:
list
- NEDAS.utils.graphics.draw_reference_vector_legend(ax, xr, yr, V, L, hw, hl, refcolor, linecolor, ref_units='')[source]
Draw a legend box with reference vector and units string.
- Parameters:
ax (matplotlib.axes.Axes) – Matplotlib axes object.
xr (float) – X-coordinate of the center of the legend box
yr (float) – Y-coordinate of the center of the legend box
V (float) – Velocity scale to be shown as the reference vector.
L (float) – Length of the reference vector.
hw (float) – Width of the arrowhead.
hl (float) – Length of the arrowhead.
refcolor (str or tuple) – Color of the background in the legend box.
linecolor (str or tuple) – Color of the reference vector.
ref_units (str, optional) – Unit label to be shown, default is ‘’.
- NEDAS.utils.graphics.draw_line(ax, data, linecolor, linewidth, linestyle, zorder)[source]
Draw line segments.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to draw the lines.
data (dict) – Dictionary containing: - ‘xy’ (list of arrays): Coordinates of points. - ‘parts’ (list of lists): Indices indicating segment divisions.
linecolor (str or tuple) – Color of the line.
linewidth (float) – Width of the line.
linestyle (str) – Style of the line (e.g., ‘-’, ‘–’, ‘:’).
zorder (int) – Drawing order (higher numbers are drawn on top).
- NEDAS.utils.graphics.draw_patch(ax, data, color, zorder)[source]
Draw a filled patch.
- Parameters:
ax (matplotlib.axes.Axes) – The axes on which to draw the lines.
data (dict) – Dictionary containing: - ‘xy’ (list of arrays): Coordinates of points. - ‘parts’ (list of lists): Indices indicating segment divisions.
color (str or tuple) – Color of the patch
zorder (int) – Drawing order (higher numbers are drawn on top).