pyiem.plot.util module#

pyiem.plot.util Plotting Utilities.

pyiem.plot.util.update_kwargs_apctx(func)[source]#

Decorate things provided by an autoplot context dict.

pyiem.plot.util.draw_features_from_shapefile(gp, name, **kwargs)[source]#

Add features as we need to.

pyiem.plot.util.ramp2df(name)[source]#

Load pyIEM color ramp into a Pandas DataFrame.

Parameters:

name (str) – the name of the bundled color ramp.

Return type:

pandas.DataFrame

pyiem.plot.util.pretty_bins(minval, maxval, bins=8)[source]#

Return a smooth binning that encloses the min and max value.

The returned array is at most the specified bins + 1 in size, but could be smaller given this algorithm and the data range.

Parameters:
  • minval (real) – minimum value to enclose.

  • maxval (real) – maximum value to enclose.

  • bins (int) – maximum number of bins to generate

Returns: np.array of bins

pyiem.plot.util.centered_bins(absmax, on=0, bins=8)[source]#

Return a smooth binning around some number.

The returned array is +1 in size of the bins specified, since we want the bin edges.

Parameters:
  • absmax (real) – positive distance from the on value for bins to enclose.

  • on (real) – where to center these bins.

  • bins (int) – number of bins to generate

Returns: np.array of bins

Place the logo.

pyiem.plot.util.fontscale(ratio, fig)[source]#

Return a font size suitable for this NDC ratio.

Parameters:
  • ratio (float) – value between 0 and 1

  • fig (matplotlib.Figure,optional) – The Figure of interest

Returns:

float

Return type:

font size

pyiem.plot.util.fitbox(fig, text, x0, x1, y0, y1, **kwargs)[source]#

Fit text into a NDC box.

Parameters:

textsize (int, optional) – First attempt this textsize to see if it fits.

pyiem.plot.util.make_panel(ndc_axbounds, fig, extent, crs, aspect, is_geoextent=False, **kwargs)[source]#

Make a GeoPanel.

Parameters:
  • ndc_axbounds (list) – the NDC coordinates of axes to create

  • extent (list) – x0,x1,y0,y1 in projected space plot extent, unless is_geoextent is based as True, then it is Geodetic.

  • crs (pyproj.CRS) – the crs of the axes

  • aspect (str) – matplotlib’s aspect of axes

  • is_geoextent (bool) – is the passed extent Geodetic?

  • sector_label (bool) – A Label that tracks what this is called

  • background (str) – background to use.

Returns:

GeoPanel

Return type:

the panel

pyiem.plot.util.sector_setter(mp, axbounds, **kwargs)[source]#

Use kwargs to set the MapPlot sector.

pyiem.plot.util.mask_outside_polygon(poly_verts, gp)[source]#

Make outside of a polygon.

POLY_VERTS is in CCW order, as this is the interior of the polygon

pyiem.plot.util.polygon_fill(mymap, geodf, data, **kwargs)[source]#

Generalize function for overlaying filled polygons on the map.

Parameters:
  • mymap (MapPlot) – The MapPlot instance

  • geodf (GeoDataFrame) – A GeoDataFrame with a geom column.

  • data (dict) – The dictionary of keys and values used for picking colors

Keyword Arguments:
  • ilabel (Optional[bool]) – should values be labelled? Defaults to False

  • lblfmt (str,optional) – format string for labels. Defaults to %s.

  • plotmissing (bool) – should geometries not included in the data be mapped? Defaults to True

  • color (str or dict) – Providing an explicit color (used for both edge and fill). Either provide one color or a dictionary to lookup a color by the mapping key.

  • fc (str or dict) – Same as color, but controls the fill color. Providing this value will over-ride any color setting.

  • ec (str or dict) – Same as color, but controls the edge color. Providing this value will over-ride any color setting.

  • zorder (int) – The zorder to use for this layer, default Z_FILL

  • lw (float) – polygon outline width

pyiem.plot.util.mask_outside_geom(gp, geom)[source]#

Create a white patch over the plot for what we want to ask out.

Parameters:
  • gp (GeoPanel) – The GeoPanel instance

  • geom (geometry)