landlab

Plotting and Visualization

Submodules

Submodules

landlab.plot.colors module

colors.py.

Created on Mon Jan 18 13:28:17 2016

@author: gtucker

colormap(name)[source]

Return named Landlab colormap as a matplotlib colormap.

Parameters:
  • name (str) – Name of colormap
  • available maps are (Currently) – ‘water’: black to light blue ‘earth’: dark olive to light sand color
earth_colormap()[source]

Return matplotlib colormap with ‘earth’ theme.

water_colormap()[source]

Return matplotlib colormap with ‘water’ theme.

landlab.plot.drainage_plot module

Plot drainage network.

drainage_plot(mg, surface='topographic__elevation', receivers=None, proportions=None, surf_cmap='gray', quiver_cmap='viridis', title='Drainage Plot')[source]

landlab.plot.event_handler module

Functions to interact with figures that plot Landlab grid data.

query_grid_on_button_press(event, grid)[source]

Print and returns node information using an imshow plot.

This function is triggered when a mouse button is pressed on the matplotlib figure connected by event. Coordinates of grid and its node attributes are queried only when the event location is within the axes of the figure. The node whose attributes are queried is the node at the center of the cell that contains the event coordinates.

This function only works with raster model grids.

Parameters:
  • event (matplotlib event) – Event associated with a figure canvas using mpl_connect().
  • grid (RasterModelGrid) – Grid containing the attributes to print.
Returns:

Dictionary containing grid query results.

Return type:

query_results

landlab.plot.graph module

plot_graph(graph, at='node, link, patch', with_id=True)[source]
plot_nodes(graph, color='r', with_id=True, markersize=10)[source]
plot_patches(graph, color='g')[source]

landlab.plot.imshow module

Methods to plot data defined on Landlab grids.

Plotting functions

imshow_grid(grid, values, **kwds) imshow_grid(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, colorbar_label=None, norm=[linear], shrink=1., color_for_closed=’black’, show_elements=False, color_for_background=None)
imshow_grid_at_cell(grid, values, **kwds) imshow_grid_at_cell(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, colorbar_label=None, norm=[linear], shrink=1., color_for_closed=’black’, color_for_background=None, show_elements=False, output=None)
imshow_grid_at_node(grid, values, **kwds) imshow_grid_at_node(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, norm=[linear], shrink=1., color_for_closed=’black’, color_for_background=None, show_elements=False, output=None)
imshow_grid(grid, values, **kwds)[source]

imshow_grid(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, colorbar_label=None, norm=[linear], shrink=1., color_for_closed=’black’, show_elements=False, color_for_background=None)

Prepare a map view of data over all nodes or cells in the grid.

Data is plotted as colored cells. If at=’node’, the surrounding cell is shaded with the value at the node at its center. If at=’cell’, the cell is shaded with its own value. Outer edges of perimeter cells are extrapolated. Closed elements are colored uniformly (default black, overridden with kwd ‘color_for_closed’); other open boundary nodes get their actual values.

values can be a field name, a regular array, or a masked array. If a masked array is provided, masked entries will be treated as if they were Landlab BC_NODE_IS_CLOSED. Used together with the color_for_closed=None keyword (i.e., “transparent”), this can allow for construction of overlay layers in a figure (e.g., only defining values in a river network, and overlaying it on another landscape).

Use matplotlib functions like xlim, ylim to modify your plot after calling imshow_grid, as desired.

This function happily works with both regular and irregular grids.

Parameters:
  • grid (ModelGrid) – Grid containing the field to plot, or describing the geometry of the provided array.
  • values (array_like, masked_array, or str) – Node or cell values, or a field name as a string from which to draw the data.
  • at (str, {'node', 'cell'}) – Tells plotter where values are defined.
  • plot_name (str, optional) – String to put as the plot title.
  • var_name (str, optional) – Variable name, to use as a colorbar label.
  • var_units (str, optional) – Units for the variable being plotted, for the colorbar.
  • grid_units (tuple of str, optional) – Units for y, and x dimensions. If None, component will look to the gri property axis_units for this information. If no units are specified there, no entry is made.
  • symmetric_cbar (bool) – Make the colormap symetric about 0.
  • cmap (str) – Name of a colormap
  • limits (tuple of float) – Minimum and maximum of the colorbar.
  • vmax (vmin,) – Alternatives to limits.
  • allow_colorbar (bool) – If True, include the colorbar.
  • colorbar_label (str or None) – The string with which to label the colorbar.
  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.
  • shrink (float) – Fraction by which to shrink the colorbar.
  • color_for_closed (str or None) – Color to use for closed elements (default ‘black’). If None, closed (or masked) elements will be transparent.
  • color_for_background (color str or other color declaration, or None) – Color to use for closed elements (default None). If None, the background will be transparent, and appear white.
  • show_elements (bool) – If True, and grid is a Voronoi, the faces will be plotted in black along with just the colour of the cell, defining the cell outlines (defaults False).
  • output (None, string, or bool) – If None (or False), the image is sent to the imaging buffer to await an explicit call to show() or savefig() from outside this function. If a string, the string should be the path to a save location, and the filename (with file extension). The function will then call plt.savefig([string]) itself. If True, the function will call plt.show() itself once plotting is complete.
imshow_grid_at_cell(grid, values, **kwds)[source]

imshow_grid_at_cell(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, colorbar_label=None, norm=[linear], shrink=1., color_for_closed=’black’, color_for_background=None, show_elements=False, output=None)

Map view of grid data over all grid cells.

Prepares a map view of data over all cells in the grid. Method can take any of the same **kwds as imshow_grid_at_node.

Parameters:
  • grid (ModelGrid) – Grid containing the field to plot, or describing the geometry of the provided array.
  • values (array_like, masked_array, or str) – Values at the cells on the grid. Alternatively, can be a field name (string) from which to draw the data from the grid.
  • plot_name (str, optional) – String to put as the plot title.
  • var_name (str, optional) – Variable name, to use as a colorbar label.
  • var_units (str, optional) – Units for the variable being plotted, for the colorbar.
  • grid_units (tuple of str, optional) – Units for y, and x dimensions. If None, component will look to the gri property axis_units for this information. If no units are specified there, no entry is made.
  • symmetric_cbar (bool) – Make the colormap symetric about 0.
  • cmap (str) – Name of a colormap
  • limits (tuple of float) – Minimum and maximum of the colorbar.
  • vmax (vmin,) – Alternatives to limits.
  • allow_colorbar (bool) – If True, include the colorbar.
  • colorbar_label (str or None) – The string with which to label the colorbar.
  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.
  • shrink (float) – Fraction by which to shrink the colorbar.
  • color_for_closed (str or None) – Color to use for closed elements (default ‘black’). If None, closed (or masked) elements will be transparent.
  • color_for_background (color str or other color declaration, or None) – Color to use for closed elements (default None). If None, the background will be transparent, and appear white.
  • show_elements (bool) – If True, and grid is a Voronoi, the faces will be plotted in black along with just the colour of the cell, defining the cell outlines (defaults False).
  • output (None, string, or bool) – If None (or False), the image is sent to the imaging buffer to await an explicit call to show() or savefig() from outside this function. If a string, the string should be the path to a save location, and the filename (with file extension). The function will then call plt.savefig([string]) itself. If True, the function will call plt.show() itself once plotting is complete.
Raises:

ValueError – If input grid is not uniform rectilinear.

imshow_grid_at_node(grid, values, **kwds)[source]

imshow_grid_at_node(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, norm=[linear], shrink=1., color_for_closed=’black’, color_for_background=None, show_elements=False, output=None)

Prepare a map view of data over all nodes in the grid.

Data is plotted as cells shaded with the value at the node at its center. Outer edges of perimeter cells are extrapolated. Closed elements are colored uniformly (default black, overridden with kwd ‘color_for_closed’); other open boundary nodes get their actual values.

values can be a field name, a regular array, or a masked array. If a masked array is provided, masked entries will be treated as if they were Landlab BC_NODE_IS_CLOSED. Used together with the color_at_closed=None keyword (i.e., “transparent”), this can allow for construction of overlay layers in a figure (e.g., only defining values in a river network, and overlaying it on another landscape).

Use matplotlib functions like xlim, ylim to modify your plot after calling imshow_grid, as desired.

Node coordinates are printed when a mouse button is pressed on a cell in the plot.

This function happily works with both regular and irregular grids.

Parameters:
  • grid (ModelGrid) – Grid containing the field to plot, or describing the geometry of the provided array.
  • values (array_like, masked_array, or str) – Node values, or a field name as a string from which to draw the data.
  • plot_name (str, optional) – String to put as the plot title.
  • var_name (str, optional) – Variable name, to use as a colorbar label.
  • var_units (str, optional) – Units for the variable being plotted, for the colorbar.
  • grid_units (tuple of str, optional) – Units for y, and x dimensions. If None, component will look to the gri property axis_units for this information. If no units are specified there, no entry is made.
  • symmetric_cbar (bool) – Make the colormap symetric about 0.
  • cmap (str) – Name of a colormap
  • limits (tuple of float) – Minimum and maximum of the colorbar.
  • vmax (vmin,) – Alternatives to limits.
  • allow_colorbar (bool) – If True, include the colorbar.
  • colorbar_label (str or None) – The string with which to label the colorbar.
  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.
  • shrink (float) – Fraction by which to shrink the colorbar.
  • color_for_closed (str or None) – Color to use for closed nodes (default ‘black’). If None, closed (or masked) nodes will be transparent.
  • color_for_background (color str or other color declaration, or None) – Color to use for closed elements (default None). If None, the background will be transparent, and appear white.
  • show_elements (bool) – If True, and grid is a Voronoi, the faces will be plotted in black along with just the colour of the cell, defining the cell outlines (defaults False).
  • output (None, string, or bool) – If None (or False), the image is sent to the imaging buffer to await an explicit call to show() or savefig() from outside this function. If a string, the string should be the path to a save location, and the filename (with file extension). The function will then call plt.savefig([string]) itself. If True, the function will call plt.show() itself once plotting is complete.

landlab.plot.network_sediment_transporter module

Created on Tue Jun 18 14:22:27 2019

@author: pfeif

plot_network_and_parcels(grid, parcels, parcel_time_index=None, map_buffer=0.1, parcel_filter=None, network_color=None, link_attribute=None, link_attribute_title=None, network_cmap='cividis', network_norm=None, network_linewidth=None, parcel_color=None, parcel_color_attribute=None, parcel_color_attribute_title=None, parcel_color_cmap='plasma', parcel_color_norm=None, parcel_size=None, parcel_size_attribute=None, parcel_size_attribute_title=None, parcel_size_norm=None, parcel_size_min=5, parcel_size_max=40, parcel_alpha=0.5, fig=None, **kwargs)[source]

Plot a river network and parcels on the river network. Intended to display the results of the NetworkSedimentTransporter component.

The river network (an instance of NetworkModelGrid) is plotted either as straight links between grid nodes, or (if the network was created using a shapefile to set network topology) as sinuous lines representing the actual link geometry.

The parcels (an instance of DataRecord) are represented as dot markers along the links, with the marker location set by parcel attribute location_at_link. The default is to plot the parcel locations at the last timestep in DataRecord, though any time index may be specified.

Use of this plotting tool is described in detail in a landlab tutorial.

Parameters:
  • grid (NetworkModelGrid) – Instance of NetworkModelGrid.
  • parcels (DataRecord) – Instance of Landlab DataRecord, with the same attribute requirements as NetworkSedimentTransporter.
  • parcel_time_index (int, time index of parcels DataRecord) – Parcel time index to plot. Default is last timestep in parcels DataRecord.
  • map_buffer (0.1) – Increase the plot extent by at least this much (default 0.1). Note, b/c of axis equal, may be more.
  • parcel_filter (boolean array of shape (number_of_parcels, )) – Filter to plot only a selection of the parcels.
  • ########################
  • Part 1 (##) –
  • network_color="k" – Uniform color for network links.
  • or (#) –
  • link_attribute (array or field name at link) – Value used to set link color. Categorical options not supported. Must be continuous.
  • link_attribute_title (str) – String to use as the title, if link_attribute is a string, it is used as the default.
  • network_cmap ("cividis") – Name of colormap for network.
  • network_norm (matplotlib color normalizer.) – https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of link_attribute.
  • linewidth will be recognized by either link coloring option. (#) –
  • network_linewidth (float) – Width of network lines (default 0.5).
  • ########################
  • Part 2 (##) –
  • parcel_color (color str) – Constant color used for parcel markers (default “k”).
  • or
  • parcel_color_attribute (parcel attribute name.) – Categorical options not supported. Must be continuous.
  • parcel_color_attribute_title (str) – String to use as the legend title. If parcel_color_attribute is a string, it is used as the default.
  • parcel_color_cmap (cmap str) – Name of colormap for variable parcel color (default “plasma”).
  • parcel_color_norm (matplotlib color normalizer.) – https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of parcel_color_attribute.
  • for parcel size use either (#) –
  • parcel_size (float) – Marker size, in points.
  • or
  • parcel_size_attribute (parcel atribute name.) – Categorical options not supported. Must be continuous.
  • parcel_size_attribute_title (str) – string to use as the title, if parcel_size_attribute is a string, it is used as the default.
  • parcel_size_norm (par) – matplotlib color normalizer. https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of parcel_size_attribute.,
  • parcel_size_min (float) – Specify the smallest size of the dot markers plotted, in units of points (default 5). Use with parcel_size_max. They will be aligned with the limits of parcel_size_norm.
  • parcel_size_max (float) – Specify the largest size of the dot markers plotted, in units of points (default 40). Use with parcel_size_min. They will be aligned with the limits of parcel_size_norm.
  • with constant or attribute, can set parcel transparency (#) –
  • parcel_alpha (float, between 0 and 1) – Specify parcel marker transparency (default 0.5).
  • Miscellaneous (###################) –
  • fig (figure object) – Default is to create a new figure object.
  • Anything else to pass to figure creation. (**kwargs) –
Returns:

Figure object.

Return type:

fig

landlab.plot.video_out module

Create mp4 animation of Landlab output.

This component allows creation of mp4 animations of output from Landlab. It does so by stitching together output from the conventional Landlab static plotting routines from plot/imshow.py.

It is compatible with all Landlab grids, though cannot handle an evolving grid as yet.

Initialize the video object vid at the start of your code, then simply call vid.add_frame(grid, data) each time you want to add a frame. At the end of the model run, call vid.produce_video().

CAUTION: This component may prove very memory-intensive. It is recommended that the total number of frames included in the output multiplied by the number of pixels (nodes) in the image not exceed XXXXXXXXX.

Due to some issues with codecs in matplotlib, at the moment on .gif output movies are recommended. If this irritates you, you can modify your own PYTHONPATH to allow .mp4 compilation (try a google search for the warning raised by this method for some hints). These (known) issues are apparently likely to resolve themselves in a future release of matplotlib.

class VideoPlotter(grid, data_centering='node', start=None, stop=None, step=None)[source]

Bases: object

Create animations of landlab output.

Create Landlab movies.

Parameters:
  • grid (RasterModelGrid) – A RasterModelGrid.
  • data_centering ({'node', 'cell'}, optional) – Where data are centered.
  • start (float, optional) – Model time at which filming starts.
  • stop (float, optional) – Model time at which filming stops.
  • step (float, optional) – Model time frequency at which frames are made.

Create Landlab movies.

Parameters:
  • grid (RasterModelGrid) – A RasterModelGrid.
  • data_centering ({'node', 'cell'}, optional) – Where data are centered.
  • start (float, optional) – Model time at which filming starts.
  • stop (float, optional) – Model time at which filming stops.
  • step (float, optional) – Model time frequency at which frames are made.
__init__(grid, data_centering='node', start=None, stop=None, step=None)[source]

Create Landlab movies.

Parameters:
  • grid (RasterModelGrid) – A RasterModelGrid.
  • data_centering ({'node', 'cell'}, optional) – Where data are centered.
  • start (float, optional) – Model time at which filming starts.
  • stop (float, optional) – Model time at which filming stops.
  • step (float, optional) – Model time frequency at which frames are made.
add_frame(grid, data, elapsed_t, **kwds)[source]

Add a frame to the video.

data can be either the data to plot (nnodes, or appropriately lengthed numpy array), or a string for grid field access.

kwds can be any of the usual plotting keywords, e.g., cmap.

clear_module()[source]

Clear internally held data.

Wipe all internally held data that would cause trouble if module were to be rerun without being reinstantiated.

initialize(grid, data_centering, start, stop, step)[source]

Set up the plotter.

A copy of the grid is required.

data_centering controls the type of data the video will be plotting.

It can be set to: “node” (default) or “cell”.

start, stop, and step control when a frame is added. They are absolute times in the model run. All are optional.

Parameters:
  • grid (RasterModelGrid) – A RasterModelGrid.
  • data_centering ({'node', 'cell'}, optional) – Where data are centered.
  • start (float) – Model time at which filming starts.
  • stop (float) – Model time at which filming stops.
  • step (float) – Model time frequency at which frames are made.
produce_video(interval=200, repeat_delay=2000, filename='video_output.gif', override_min_max=None)[source]

Finalize and save the video of the data.

Parameters:
  • interval (int, optional) – Interval between frames in milliseconds.
  • repeat_delay (int, optional) – Repeat delay before restart in milliseconds.
  • filename (str, optional) – Name of the file to save in the present working directory. At present, only .gifs will implement reliably without tweaking Python’s PATHs.
  • override_min_max (tuple of float) – Minimum and maximum for the scale on the plot as (min, max).

Module contents

imshow_grid(grid, values, **kwds)[source]

imshow_grid(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, colorbar_label=None, norm=[linear], shrink=1., color_for_closed=’black’, show_elements=False, color_for_background=None)

Prepare a map view of data over all nodes or cells in the grid.

Data is plotted as colored cells. If at=’node’, the surrounding cell is shaded with the value at the node at its center. If at=’cell’, the cell is shaded with its own value. Outer edges of perimeter cells are extrapolated. Closed elements are colored uniformly (default black, overridden with kwd ‘color_for_closed’); other open boundary nodes get their actual values.

values can be a field name, a regular array, or a masked array. If a masked array is provided, masked entries will be treated as if they were Landlab BC_NODE_IS_CLOSED. Used together with the color_for_closed=None keyword (i.e., “transparent”), this can allow for construction of overlay layers in a figure (e.g., only defining values in a river network, and overlaying it on another landscape).

Use matplotlib functions like xlim, ylim to modify your plot after calling imshow_grid, as desired.

This function happily works with both regular and irregular grids.

Parameters:
  • grid (ModelGrid) – Grid containing the field to plot, or describing the geometry of the provided array.
  • values (array_like, masked_array, or str) – Node or cell values, or a field name as a string from which to draw the data.
  • at (str, {'node', 'cell'}) – Tells plotter where values are defined.
  • plot_name (str, optional) – String to put as the plot title.
  • var_name (str, optional) – Variable name, to use as a colorbar label.
  • var_units (str, optional) – Units for the variable being plotted, for the colorbar.
  • grid_units (tuple of str, optional) – Units for y, and x dimensions. If None, component will look to the gri property axis_units for this information. If no units are specified there, no entry is made.
  • symmetric_cbar (bool) – Make the colormap symetric about 0.
  • cmap (str) – Name of a colormap
  • limits (tuple of float) – Minimum and maximum of the colorbar.
  • vmax (vmin,) – Alternatives to limits.
  • allow_colorbar (bool) – If True, include the colorbar.
  • colorbar_label (str or None) – The string with which to label the colorbar.
  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.
  • shrink (float) – Fraction by which to shrink the colorbar.
  • color_for_closed (str or None) – Color to use for closed elements (default ‘black’). If None, closed (or masked) elements will be transparent.
  • color_for_background (color str or other color declaration, or None) – Color to use for closed elements (default None). If None, the background will be transparent, and appear white.
  • show_elements (bool) – If True, and grid is a Voronoi, the faces will be plotted in black along with just the colour of the cell, defining the cell outlines (defaults False).
  • output (None, string, or bool) – If None (or False), the image is sent to the imaging buffer to await an explicit call to show() or savefig() from outside this function. If a string, the string should be the path to a save location, and the filename (with file extension). The function will then call plt.savefig([string]) itself. If True, the function will call plt.show() itself once plotting is complete.
imshow_grid_at_node(grid, values, **kwds)[source]

imshow_grid_at_node(grid, values, plot_name=None, var_name=None, var_units=None, grid_units=None, symmetric_cbar=False, cmap=’pink’, limits=(values.min(), values.max()), vmin=values.min(), vmax=values.max(), allow_colorbar=True, norm=[linear], shrink=1., color_for_closed=’black’, color_for_background=None, show_elements=False, output=None)

Prepare a map view of data over all nodes in the grid.

Data is plotted as cells shaded with the value at the node at its center. Outer edges of perimeter cells are extrapolated. Closed elements are colored uniformly (default black, overridden with kwd ‘color_for_closed’); other open boundary nodes get their actual values.

values can be a field name, a regular array, or a masked array. If a masked array is provided, masked entries will be treated as if they were Landlab BC_NODE_IS_CLOSED. Used together with the color_at_closed=None keyword (i.e., “transparent”), this can allow for construction of overlay layers in a figure (e.g., only defining values in a river network, and overlaying it on another landscape).

Use matplotlib functions like xlim, ylim to modify your plot after calling imshow_grid, as desired.

Node coordinates are printed when a mouse button is pressed on a cell in the plot.

This function happily works with both regular and irregular grids.

Parameters:
  • grid (ModelGrid) – Grid containing the field to plot, or describing the geometry of the provided array.
  • values (array_like, masked_array, or str) – Node values, or a field name as a string from which to draw the data.
  • plot_name (str, optional) – String to put as the plot title.
  • var_name (str, optional) – Variable name, to use as a colorbar label.
  • var_units (str, optional) – Units for the variable being plotted, for the colorbar.
  • grid_units (tuple of str, optional) – Units for y, and x dimensions. If None, component will look to the gri property axis_units for this information. If no units are specified there, no entry is made.
  • symmetric_cbar (bool) – Make the colormap symetric about 0.
  • cmap (str) – Name of a colormap
  • limits (tuple of float) – Minimum and maximum of the colorbar.
  • vmax (vmin,) – Alternatives to limits.
  • allow_colorbar (bool) – If True, include the colorbar.
  • colorbar_label (str or None) – The string with which to label the colorbar.
  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.
  • shrink (float) – Fraction by which to shrink the colorbar.
  • color_for_closed (str or None) – Color to use for closed nodes (default ‘black’). If None, closed (or masked) nodes will be transparent.
  • color_for_background (color str or other color declaration, or None) – Color to use for closed elements (default None). If None, the background will be transparent, and appear white.
  • show_elements (bool) – If True, and grid is a Voronoi, the faces will be plotted in black along with just the colour of the cell, defining the cell outlines (defaults False).
  • output (None, string, or bool) – If None (or False), the image is sent to the imaging buffer to await an explicit call to show() or savefig() from outside this function. If a string, the string should be the path to a save location, and the filename (with file extension). The function will then call plt.savefig([string]) itself. If True, the function will call plt.show() itself once plotting is complete.
plot_network_and_parcels(grid, parcels, parcel_time_index=None, map_buffer=0.1, parcel_filter=None, network_color=None, link_attribute=None, link_attribute_title=None, network_cmap='cividis', network_norm=None, network_linewidth=None, parcel_color=None, parcel_color_attribute=None, parcel_color_attribute_title=None, parcel_color_cmap='plasma', parcel_color_norm=None, parcel_size=None, parcel_size_attribute=None, parcel_size_attribute_title=None, parcel_size_norm=None, parcel_size_min=5, parcel_size_max=40, parcel_alpha=0.5, fig=None, **kwargs)[source]

Plot a river network and parcels on the river network. Intended to display the results of the NetworkSedimentTransporter component.

The river network (an instance of NetworkModelGrid) is plotted either as straight links between grid nodes, or (if the network was created using a shapefile to set network topology) as sinuous lines representing the actual link geometry.

The parcels (an instance of DataRecord) are represented as dot markers along the links, with the marker location set by parcel attribute location_at_link. The default is to plot the parcel locations at the last timestep in DataRecord, though any time index may be specified.

Use of this plotting tool is described in detail in a landlab tutorial.

Parameters:
  • grid (NetworkModelGrid) – Instance of NetworkModelGrid.
  • parcels (DataRecord) – Instance of Landlab DataRecord, with the same attribute requirements as NetworkSedimentTransporter.
  • parcel_time_index (int, time index of parcels DataRecord) – Parcel time index to plot. Default is last timestep in parcels DataRecord.
  • map_buffer (0.1) – Increase the plot extent by at least this much (default 0.1). Note, b/c of axis equal, may be more.
  • parcel_filter (boolean array of shape (number_of_parcels, )) – Filter to plot only a selection of the parcels.
  • ########################
  • Part 1 (##) –
  • network_color="k" – Uniform color for network links.
  • or (#) –
  • link_attribute (array or field name at link) – Value used to set link color. Categorical options not supported. Must be continuous.
  • link_attribute_title (str) – String to use as the title, if link_attribute is a string, it is used as the default.
  • network_cmap ("cividis") – Name of colormap for network.
  • network_norm (matplotlib color normalizer.) – https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of link_attribute.
  • linewidth will be recognized by either link coloring option. (#) –
  • network_linewidth (float) – Width of network lines (default 0.5).
  • ########################
  • Part 2 (##) –
  • parcel_color (color str) – Constant color used for parcel markers (default “k”).
  • or
  • parcel_color_attribute (parcel attribute name.) – Categorical options not supported. Must be continuous.
  • parcel_color_attribute_title (str) – String to use as the legend title. If parcel_color_attribute is a string, it is used as the default.
  • parcel_color_cmap (cmap str) – Name of colormap for variable parcel color (default “plasma”).
  • parcel_color_norm (matplotlib color normalizer.) – https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of parcel_color_attribute.
  • for parcel size use either (#) –
  • parcel_size (float) – Marker size, in points.
  • or
  • parcel_size_attribute (parcel atribute name.) – Categorical options not supported. Must be continuous.
  • parcel_size_attribute_title (str) – string to use as the title, if parcel_size_attribute is a string, it is used as the default.
  • parcel_size_norm (par) – matplotlib color normalizer. https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html Default is linear between min and max of parcel_size_attribute.,
  • parcel_size_min (float) – Specify the smallest size of the dot markers plotted, in units of points (default 5). Use with parcel_size_max. They will be aligned with the limits of parcel_size_norm.
  • parcel_size_max (float) – Specify the largest size of the dot markers plotted, in units of points (default 40). Use with parcel_size_min. They will be aligned with the limits of parcel_size_norm.
  • with constant or attribute, can set parcel transparency (#) –
  • parcel_alpha (float, between 0 and 1) – Specify parcel marker transparency (default 0.5).
  • Miscellaneous (###################) –
  • fig (figure object) – Default is to create a new figure object.
  • Anything else to pass to figure creation. (**kwargs) –
Returns:

Figure object.

Return type:

fig