Plotting#

easysnowdata.plotting#

Plotting helpers: maps that are true to scale, time series on calendar dates.

Nothing here is required to use the data: every product plots with plain xarray and geopandas. What these helpers add is the map furniture and the labelling conventions the gallery follows, so an example is one call rather than fifteen lines of matplotlib:

  • map() — one raster on equal-aspect axes with a matched colorbar, a scale bar, a light latitude/longitude graticule, and an optional web basemap. Geographic (EPSG:4326) data get a latitude-corrected aspect and a warning, because a degree of longitude is not a degree of latitude.

  • categorical() — the same for a classified raster, drawing its colours and legend from the CF flag_values / flag_meanings / flag_colors attributes easysnowdata.processing.categorical writes.

  • points() — a GeoDataFrame of stations (or any vector layer) over a basemap, coloured by a column with a legend or colorbar placed outside.

  • timeseries() — one line per station (or other dimension) against calendar dates, with long name [units] axis labels. by_water_year overlays water years on one October-to-September axis.

  • label() — "long name [units]" from an object’s attrs, the one convention every axis label here follows (units in square brackets).

Every piece of furniture is a keyword argument (scalebar=False, graticule=False, basemap="CartoDB.Positron" …), and every function returns the matplotlib Axes so anything can be added afterwards.

map

Draw one raster as a map with the package's conventions.

categorical

Plot a categorical DataArray with one colour per class and a legend.

points

Draw a GeoDataFrame (stations, basins) over a basemap with the map conventions.

timeseries

Plot a time series, one line per hue value, against calendar dates.

label

"long name [units]" from obj (a DataArray, Dataset or attrs mapping).

finish_map

Apply the map conventions to ax: aspect, labels, scale bar, graticule, basemap.

add_scalebar

Add a small scale bar (matplotlib_scalebar) to ax.

add_graticule

Draw light latitude/longitude lines on ax and label them on the frame.

add_basemap

Draw web tiles under the data on ax (contextily), warped to crs.

add_outline

Draw gdf (boundaries, basins, glaciers) over a map, in the map's CRS.

colormap_from_flags

Return (cmap, norm, flags_df) for a categorical array's CF flags.

legend_handles

(handles, labels) for ax.legend from the CF flags (underscores → spaces).

register_colormap

Register a ListedColormap under name with matplotlib and return it.