pyiem.plot.geoplot module#

Plotting utility for generating maps, windroses and everything else under the sun.

This module provides a wrapper around Basemap and windrose packages. It tries to be general so to work for others, but may contain some unfortunate hard coded values. Bad daryl!

Example

Here is a basic example of usage.

>>> from pyiem.plot.geoplot import MapPlot
>>> m = MapPlot(sector='conus', title='My Fancy Title')
>>> m.postprocess(filename='myplot.png')
>>> m.close()
pyiem.plot.geoplot.load_bounds(filebase)[source]#

Load bounds file

Parameters:

filebase (str) – the basename of the file containing the data

Returns:

numpy 2d array of the data

class pyiem.plot.geoplot.MapPlot(sector='iowa', **kwargs)[source]#

Bases: object

An object representing a matplotlib figure.

An object that allows one to quickly and easily generate map plots of data with some customization possible. This is what drives most of the plots you see on the IEM website.

Example

Here is an example of usage:

mplot = MapPlot(sector='midwest', title='My Plot Title')
mplot.plot_values([-99,-95], [44,45], ['hi','there'])
mplot.postprocess(filename='test.png')
mplot.close()
fig#

figure object

Type:

matplotlib.Figure

ax#

main figure plot axes

Type:

matplotlib.Axes

close()[source]#

Close the figure in the case of batch processing

draw_usdm(valid=None, filled=True, hatched=False, **kwargs)[source]#

Overlay the US Drought Monitor

This utilizes a GeoJSON web service provided by the IEM. The provided date to this method is passed to the web service which rectifies the date to provide the USDM analysis valid for that date. If no date is specified, the current analysis is plotted.

Parameters:
  • valid (str or datetime.date) – The valid time to plot this USDM

  • filled (boolean) – Should we draw lines or filled polygons

  • hatched (boolean) – Should we use hatch filling

  • alpha (float) – Alpha value for the polygons, default 0.5.

Returns:

date that the USDM is valid for

draw_radar_ptype_legend()[source]#

Draw a legend for radar precipitation type.

draw_colorbar(clevs, cmap, norm, **kwargs)[source]#

Draw the colorbar on the structed plot using self.cax.

Parameters:
  • clevs (list) – The levels used in the classification

  • cmap (matplotlib.colormap) – The colormap

  • norm (normalize) – The value normalizer

  • title (str,optional) – Place a label on the side, adjusts the plot accordingly to allow this text to fit, no multiline please!

  • spacing (str,optional) – should the colorbar be uniform or proportional, defaults to uniform

plot_station(data, **kwargs)[source]#

Plot values on a map in a station plot like manner.

Parameters:
  • data (list) – list of dicts with station data to plot

  • fontsize (int) – font size to use for plotted text

plot_values(lons, lats, vals, fmt='%s', valmask=None, color='#000000', textsize=14, labels=None, labeltextsize=10, labelcolor='#000000', showmarker=False, labelbuffer=25, outlinecolor='#FFFFFF', zorder=None, **kwargs)[source]#

Plot values onto the map

Parameters:
  • lons (list) – longitude values to use for placing vals

  • lats (list) – latitude values to use for placing vals

  • vals (list) – actual values to place on the map

  • fmt (str, optional) – Format specification to use for representing the values. For example, the default is ‘%s’.

  • valmask (list, optional) – Boolean list to use as masking of the vals while adding to the map.

  • color (str, list, optional) – Color to use while plotting the vals. This can be a list to specify each color to use with each value.

  • textsize (str, optional) – Font size to draw text. labels (list, optional): Optional list of labels to place below the plotting of vals

  • labeltextsize (int, optional) – Size of the label text

  • labelcolor (str, optional) – Color to use for drawing labels

  • showmarker (bool, optional) – Place a marker on the map for the label

  • labelbuffer (int) – pixel buffer around labels, a value of 0 disables the label culling logic.

  • outlinecolor (color) – color to use for text outlines

  • zorder (int or list, optional) – zorder to use for plotting.

  • textoutlinewidth (int) – width of the font outline, default 3. A value <= 0 disables text outlines.

  • isolated (bool) – Only compute label collision against labels within this plot_values call. Default false

  • backgroundcolor (color) – color to use for the background of the label text, default is None.

scatter(lons, lats, vals, clevs, **kwargs)[source]#

Draw points on the map

Parameters:
  • lons (list) – longitude values

  • lats (list) – latitude values

  • vals (list) – Data values for the points to use for colormapping

  • clevs (list) – Levels to use for ramp

  • **kwargs – additional options draw_colorbar (bool, optional): Draw a colorbar, default True.

hexbin(lons, lats, vals, clevs, **kwargs)[source]#

hexbin wrapper.

Parameters:

draw_colorbar (bool,optional) – Draw colorbar default True.

imshow(grid, affine, crs, clevs=None, **kwargs)[source]#

Reprojects an image onto each MapPanel and then draws it.

Parameters:
  • grid (np.ndarray) – The 2-D data to draw

  • affine (Affine) – The affine transformation of the image

  • crs (str) – The CRS of the image

  • clevs (list, Optional) – The levels to use for the colormap

Keyword Arguments:
  • draw_colorbar (bool,optional) – Draw colorbar default True.

  • cmap (str,optional) – The colormap to use, default jet.

  • extend (str,optional) – The extend value for the colormap.

  • clip_on (bool,optional) – Clip the image to the map region.

pcolormesh(lons, lats, vals, clevs, **kwargs)[source]#

Opinionated mpl.pcolormesh wrapper.

If you supply a lons in the same shape of the vals, this method will tack on an extra row and column to make matplotlib happy. If you do not want this, then pass your own lons + lats that is 1 column and 1 row greater than vals.

Parameters:

draw_colorbar (bool,optional) – Draw colorbar default True.

draw_mask(sector=None)[source]#

Draw a mask on the main axes.

If sector is not provided, this attempts to intelligently to the masking the user wants.

Parameters:

sector (str,optional) – Hard code what type of sector masking should happen.

contourf(lons, lats, vals, clevs, **kwargs)[source]#

Contourf

Parameters:
  • ilabel (boolean,optional) – Should we label contours

  • iline (boolean,optional) – should we draw contour lines

  • lblformat (str,optional) – Format string for labeling contours, %.0f. draw_colorbar (bool,optional): Draw colorbar default True.

  • linewidths (float,optional) – Line width(s) for contour lines

Returns:

The values used for plotting, maybe after gridding

Return type:

vals (np.array)

fill_climdiv(data, **kwargs)[source]#

Fill climate divisions using provided data dictionary

Parameters:

data (dict) – A dictionary of climate division IDs and values

fill_ugcs(data, **kwargs)[source]#

Overlay filled UGC geometries using bundled geometries.

Note the importance of the is_firewx flag. This determines which UGC database to look at in the face of ambiquity.

Note that this will fail when provided a data dictionary that has both zones and counties. It is recommended to plot from application logic with your own geometries in this instance.

Parameters:
  • data (dict) – A dictionary of 6 char UGC code keys and values

  • bins (list, optional) – Bins to use for cloropleth, default 0:101:10

  • color (dict, optional) – Hard code what each UGC should display as for color.

  • discontinued (bool, optional) – Should we include discontinued UGCs within the baseline geodata for plotting, default is False.

  • is_firewx (bool, optional) – Are we plotting fire weather zones?

  • draw_colorbar (bool, optional) – Should a color bar be generated, default is True.

  • plotmissing (bool, optional) – Should missing UGC data be plotted?

  • labels (dict, optional) – UGC indexed dictionary to use for labeling.

  • lblformat (str, optional) – Format string for labels, default %s.

  • missingval (str, optional) – value to use when labelling UGCs with missing values, defaults to ‘-‘.

fill_states(data, **kwargs)[source]#

Add overlay of filled state polygons

draw_fema_regions(color='k', **kwargs)[source]#

Overlay FEMA Regions.

Parameters:

color (str)

fill_fema_regions(data, **kwargs)[source]#

Add overlay of filled polygons for FEMA Regions.

Data is dictionary-ish and keys should be ints!

draw_cwas(color='k', **kwargs)[source]#

Overlay CWA Borders

Draw the CWA border lines on the map.

Parameters:
  • color (str) – The color to draw the CWA borders with

  • kwargs (dict, optional) – Parameters passed to matplotlib for plotting

fill_rfc(data, **kwargs)[source]#

Add overlay of filled polygons for NWS RFCs.

Data is dictionary-ish. Note that the ids used here are the WMO center IDs (ie TAR) and not basin ids (ie NERFC)

fill_cwsu(data, **kwargs)[source]#

Add overlay of filled polygons for NWS CWSUs.

Data is dictionary-ish.

fill_cwas(data, **kwargs)[source]#

Add overlay of filled polygons for NWS Forecast Offices.

Method adds a colorized overlay of NWS Forecast Offices based on a data dictionary of values provided. This method also places a color bar on the image.

Parameters:
  • data (dict) – Dictionary of values with keys representing the 3 char or 4 char idenitifer for the WFO. This assumes the 3 char sites are the K ones.

  • ilabel (bool) – Should we label?

drawcities(**kwargs)[source]#

Overlay some cities

Parameters:
  • minpop (int,optional) – Minimum population to consider for plotting.

  • labelbuffer (int) – approximate number of pixels to compute overlap

  • textsize (int) – size of the text

  • color (str) – color to plot the text with

  • outlinecolor (str) – color to outline the text with

  • isolated (bool) – Cause plot_values to do label collision against only labels from drawing cities. Default False.

drawcounties(color='k')[source]#

Draw counties onto the map

Parameters:

color (color,optional) – line color to use

postprocess(**kwargs)[source]#

Postprocessing.

Parameters:
  • filename (str) – file to save output to.

  • web (bool) – Write result to sys.stdout, default False.

  • memcache (obj) – write image to memcache

  • memcachekey (str) – key to use when writing to memcache.

  • memcacheexpire (int) – how long should we persist in memcache, default is 300.

  • pqstr (str) – Do pqinsert with the following LDM product name.

overlay_roadcond(valid=None)[source]#

Overlay Iowa Winter Road Conditions.

Parameters:

valid (datetime.datetime) – Valid time for NEXRAD overlay.

overlay_nexrad(valid=None, product='N0Q', caxpos=None)[source]#

Overlay an IEM NEXRAD Composite Image.

Parameters:
  • valid (datetime.datetime) – Valid time for NEXRAD overlay.

  • product (str) – either N0Q or N0R for the mosaic type.

  • caxpos (array-like) – matplotlib.axes.set_position value for the colorbar. Defaults to something in the upper-right.

Returns:

valid time of the NEXRAD, or None if not found.