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

  • are (Currently available maps) – ‘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, axes=None)[source]#

Plot elements of a graph.

Parameters:
  • graph (graph-like) – A landlab graph-like object.

  • at (str or iterable of str) – Comma-separated list of elements to plot.

  • with_id (str, iterable of str or bool) – Indicate which elements should be plotted with their corresponding id. Either a comma-separated list of grid elements or True to include ids for all elements of False for no elements.

  • axes (, optional) – Add the plot to an existing matplotlib Axes, otherwise, create a new one.

Returns:

The Axes containing the plot.

Return type:

Axes

plot_nodes(graph, color='r', with_id=True, markersize=4)[source]#
plot_patches(graph, color='g', with_id=False)[source]#

landlab.plot.imshow module#

Methods to plot data defined on Landlab grids.

Plotting functions#

imshow_grid(grid, values, **kwds)

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

imshow_grid_at_cell(grid, values, **kwds)

Map view of grid data over all grid cells.

imshow_grid_at_node(grid, values, **kwds)

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

class ModelGridPlotterMixIn[source]#

Bases: object

MixIn that provides plotting functionality.

Inhert from this class to provide a ModelDataFields object with the method function, imshow, that plots a data field.

imshow(*args, **kwds)[source]#

Plot a data field.

This is a wrapper for plot.imshow_grid, and can take the same keywords. See that function for full documentation.

Parameters:

values (str, or array-like) – Name of a field or an array of values to plot.

See also

landlab.plot.imshow_grid

LLCATS

GINF

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

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

  • alpha (array-like or scalar or None, optional) – Set the transparency.

  • limits (tuple of float) – Minimum and maximum of the colorbar.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – 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]#

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.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – 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]#

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 grid 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.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – 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.

  • ########################

  • 1 (## Part) –

  • 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.

  • option. (# linewidth will be recognized by either link coloring) –

  • network_linewidth (float) – Width of network lines (default 0.5).

  • ########################

  • 2 (## Part) –

  • 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.

  • either (# for parcel size use) –

  • 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.

  • attribute (# with constant or) –

  • transparency (can set parcel) –

  • 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.

  • creation. (**kwargs Anything else to pass to figure) –

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]#

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

  • alpha (array-like or scalar or None, optional) – Set the transparency.

  • limits (tuple of float) – Minimum and maximum of the colorbar.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – 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]#

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 grid 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.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – 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.

imshowhs_grid(grid, values, **kwds)[source]#

Prepare a map view of data over all nodes in the grid using a hillshade topography map in the background.

Data are 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 (with the color being controlled by the color_for_closed keyword); 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 are treated as if they were landlab CLOSED nodes. If closed nodes are also set to be transparent (i.e. color_for_closed=None), this can allow for the construction of overlying layers in a figure (e.g., only defining values in a river network, and then overlaying it on another landscape).

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

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

Note

For now, this function only works with RasterModelGrid.

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_name_two (str, optional) – Variable name of second layer, 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 grid property axis_units for this information. If no units are specified there, no entry is made.

  • symmetric_cbar (bool) – Make the colormap symmetric about 0.

  • cmap (str) – Name of a colormap

  • limits (tuple of float) – Minimum and maximum of the colorbar.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – Alternatives to limits.

  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.

  • ticks_km (bool, optional) – Display ticks in km instead of m

  • allow_colorbar (bool) – If True, include the colorbar.

  • shrink (float) – Fraction by which to shrink the colorbar.

  • color_for_closed (str or None) – Color to use for closed nodes (default None). If None, (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.

  • 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 str, 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.

  • fontweight_xlabel (str, optional) – Weight of x label. The default is ‘bold’.

  • fontweight_ylabel (str, optional) – Weight of y label. The default is ‘bold’.

  • plot_type ({"DEM", "Hillshade", "Drape1", "Drape2"}, optional) –

    The type of plot that will be plotted.

    • ’DEM’: Display a digital elevation map underlain by a shaded relief, based on the same DEM (‘topographic__elevation’)

    • ’Hillshade’: Display the shaded relief, of the provided DEM (‘topographic__elevation’)

    • ’Drape1’: Display any kind of provided layer on top of a shaded relief provided in the ‘topographic__elevation’ field

    • ’Drape2’: Display two layers on top of a shaded relief provided in the ‘topographic__elevation’ field

    The default is “DEM”.

  • drape1 (array_like, masked_array) – Node values to plot on top of a hillshade map. The default is None.

  • drape2 (array_like, masked_array) – Node values to plot on top of drape1 and a hillshade map. The default is None.

  • cmap2 (str) – Name of a colormap for drape 2. The default is None.

  • vertical_exa (float, optional) – Vertical exaggeration of hillshade map. The default is None.

  • azdeg (float, optional) – Azimuth of the light source. The default is 315.

  • altdeg (float, optional) – Elevation of the light source. The default is 65.

  • thres_drape1 (float, optional) – Threshold below which drape1 is made transparent. The default is None.

  • alpha (float (0-1), optional) – Transparency of DEM/Drape1 . The default is None.

  • thres_drape2 (float, optional) – Threshold below which drape2 is made transparent. The default is None.

  • alpha2 (float (0-1), optional) – Transparency of Drape2 . The default is None.

  • add_double_colorbar (bool, optional) – Add a double colorbar when two drapes are plotted. The default is False.

  • plt_contour (bool, optional) – Add contour lines to elevation plot. The default is False.

  • contour_nb (int, optional) – Number of contour lines. The default is 50.

  • default_fontsize (float, optional) – Default font size for plot labels. The default is 10.

  • cbar_height (percentage, optional) – Height of colorbar as a percentage of the figure. The default is 5%.

  • cbar_width (percentage, optional) – Width of colorbar in percentage of figure. The default is 30%.

  • cbar_or (str, optional) – Orientation of colorbar. The default is “horizontal”.

  • cbar_loc (str, optional) – Location of colorbar. The default is “lower right”.

  • bbox_to_anchor (vector, optional) – Bounding box to anchor. The default is (0, 0, 1, 1).

  • cbar_ticks_position (str, optional) – location of colorbar ticks (below or on top of the colorbar). The default is “top”.

  • cbar_ticks_position2 (str, optional) – location of colorbar ticks for colorbar of Drape2 (below or on top of the colorbar). The default is “bottom”.

  • colorbar_label_y (float, optional) – location of colorbar label with respect to the colorbar in y direction. The default is -40.

  • colorbar_label_x (float , optional) – location of colorbar label with respect to the colorbar in x direction. The default is 0.5.

  • cbar_tick_size (float, optional) – Colorbar tick size. The default is 10.

  • cbar_label_color (str, optional) – Colorbar tick color. The default is ‘black’.

  • cbar_label_fontweight (str, optional) – Colorbar font weight. The default is ‘bold’.

  • add_label_bbox (bool, optional) – Add a bbox surrounding the colorbar label. The default is False.

  • y_label_offSet_var_1 (float, optional) – Offset of ylabel on colorbar of first variable in plot with two overlaying plots. The default is 3.0.

  • y_label_offSet_var_2 (float, optional) – Offset of ylabel on colorbar of first variable in plot with two overlaying plots. The default is -1.25.

Returns:

Axis of the plot if output keyword is True.

Return type:

ax

imshowhs_grid_at_node(grid, values, **kwds)[source]#

Prepare a map view of data over all nodes in the grid using a hillshade topography map in the background.

Data are 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 (with the color being controlled by the color_for_closed keyword); 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 are treated as if they were landlab CLOSED nodes. If closed nodes are also set to be transparent (i.e. color_for_closed=None), this can allow for the construction of overlying layers in a figure (e.g., only defining values in a river network, and then overlaying it on another landscape).

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

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

Note

For now, this function only works with RasterModelGrid.

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_name_two (str, optional) – Variable name of second layer, 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 grid property axis_units for this information. If no units are specified there, no entry is made.

  • symmetric_cbar (bool) – Make the colormap symmetric about 0.

  • cmap (str) – Name of a colormap

  • limits (tuple of float) – Minimum and maximum of the colorbar.

  • vmin (floats) – Alternatives to limits.

  • vmax (floats) – Alternatives to limits.

  • norm (matplotlib.colors.Normalize) – The normalizing object which scales data, typically into the interval [0, 1]. Ignore in most cases.

  • ticks_km (bool, optional) – Display ticks in km instead of m

  • allow_colorbar (bool) – If True, include the colorbar.

  • shrink (float) – Fraction by which to shrink the colorbar.

  • color_for_closed (str or None) – Color to use for closed nodes (default None). If None, (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.

  • 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 str, 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.

  • fontweight_xlabel (str, optional) – Weight of x label. The default is ‘bold’.

  • fontweight_ylabel (str, optional) – Weight of y label. The default is ‘bold’.

  • plot_type ({"DEM", "Hillshade", "Drape1", "Drape2"}, optional) –

    The type of plot that will be plotted.

    • ’DEM’ (the default): Display a digital elevation map underlain by a shaded relief, based on the same DEM (‘topographic__elevation’)

    • ’Hillshade’: Display the shaded relief, of the provided DEM (‘topographic__elevation’)

    • ’Drape1’: Display any kind of provided layer on top of a shaded relief provided in the ‘topographic__elevation’ field

    • ’Drape2’: Display two layers on top of a shaded relief provided in the ‘topographic__elevation’ field

    The default is “DEM”.

  • drape1 (array_like, masked_array) – Node values to plot on top of a hillshade map. The default is None.

  • drape2 (array_like, masked_array) – Node values to plot on top of drape1 and a hillshade map. The default is None.

  • cmap2 (str) – Name of a colormap for drape 2. The default is None.

  • vertical_exa (float, optional) – Vertical exaggeration of hillshade map. The default is None.

  • azdeg (float, optional) – Azimuth of the light source. The default is 315.

  • altdeg (float, optional) – Elevation of the light source. The default is 65.

  • thres_drape1 (float, optional) – Threshold below which drape1 is made transparent. The default is None.

  • alpha (float (0-1), optional) – Transparency of DEM/Drape1 . The default is None.

  • thres_drape2 (float, optional) – Threshold below which drape2 is made transparent. The default is None.

  • alpha2 (float (0-1), optional) – Transparency of Drape2 . The default is None.

  • add_double_colorbar (bool, optional) – Add a double colorbar when two drapes are plotted. The default is False.

  • plt_contour (bool, optional) – Add contour lines to elevation plot. The default is False.

  • contour_nb (int, optional) – Number of contour lines. The default is 50.

  • default_fontsize (float, optional) – Default font size for plot labels. The default is 10.

  • cbar_height (percentage, optional) – Height of colorbar as a percentage of the figure. The default is 5%.

  • cbar_width (percentage, optional) – Width of colorbar in percentage of figure. The default is 30%.

  • cbar_or (str, optional) – Orientation of colorbar. The default is “horizontal”.

  • cbar_loc (str, optional) – Location of colorbar. The default is “lower right”.

  • bbox_to_anchor (vector, optional) – Bounding box to anchor. The default is (0, 0, 1, 1).

  • cbar_ticks_position (str, optional) – Location of colorbar ticks (below or on top of the colorbar). The default is “top”.

  • cbar_ticks_position2 (str, optional) – Location of colorbar ticks for colorbar of Drape2 (below or on top of the colorbar). The default is “bottom”.

  • colorbar_label_y (float, optional) – Location of colorbar label with respect to the colorbar in y direction. The default is -40.

  • colorbar_label_x (float , optional) – Location of colorbar label with respect to the colorbar in x direction. The default is 0.5.

  • cbar_tick_size (float, optional) – Colorbar tick size. The default is 10.

  • cbar_label_color (str, optional) – Colorbar tick color. The default is ‘black’.

  • cbar_label_fontweight (str, optional) – Colorbar font weight. The default is ‘bold’.

  • add_label_bbox (bool, optional) – Add a bbox surrounding the colorbar label. The default is False.

  • y_label_offSet_var_1 (float, optional) – Offset of ylabel on colorbar of first variable in plot with two overlaying plots. The default is 3.0.

  • y_label_offSet_var_2 (float, optional) – Offset of ylabel on colorbar of first variable in plot with two overlaying plots. The default is -1.25.

Returns:

Axis of the plot if output keyword is True.

Return type:

ax

plot_graph(graph, at='node,link,patch', with_id=True, axes=None)[source]#

Plot elements of a graph.

Parameters:
  • graph (graph-like) – A landlab graph-like object.

  • at (str or iterable of str) – Comma-separated list of elements to plot.

  • with_id (str, iterable of str or bool) – Indicate which elements should be plotted with their corresponding id. Either a comma-separated list of grid elements or True to include ids for all elements of False for no elements.

  • axes (, optional) – Add the plot to an existing matplotlib Axes, otherwise, create a new one.

Returns:

The Axes containing the plot.

Return type:

Axes

plot_layers(elevation_at_layer, x=None, sea_level=0.0, color_water=(0.8, 1.0, 1.0), color_bedrock=(0.8, 0.8, 0.8), color_layer=None, layer_line_width=0.5, layer_line_color='k', title=None, x_label='Distance', y_label='Elevation', legend_location='lower left')[source]#

Plot a stack of sediment layers as a cross section.

Create a plot of the elevation sediment layers, including surfaces for sea level and bedrock.

Parameters:
  • elevation_at_layer (array-like of shape (n_layers, n_stacks)) – Elevation to each layer along the profile. Layers are provided row-by-row, with the bottom-most layer being the first row.

  • x (array-like, optional) – Distance to each stack along the cross-section. If not provided, stack number will be used.

  • sea_level (float, optional) – Elevation of sea level.

  • color_water (tuple of float, optional) – Tuple of (red, green, blue) values for water.

  • color_bedrock (tuple of float, optional) – Tuple of (red, green, blue) values for bedrock.

  • color_layer (string, optional) – Colormap to use to color in the layers.

  • layer_line_width (float, optional) – Width of line used to plot layer surfaces.

  • layer_line_color (string, optional) – Color of the line used to plot layer surfaces.

  • title (string, optional) – Text to be used for the graph’s title. The default is to not include a title.

  • x_label (string, optional) – Text to be used for the x (horizontal) axis label.

  • y_label (string, optional) – Text to be used for the y (vertical) axis label.

  • legend_location (string, optional) – Where to put the legend.

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.

  • ########################

  • 1 (## Part) –

  • 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.

  • option. (# linewidth will be recognized by either link coloring) –

  • network_linewidth (float) – Width of network lines (default 0.5).

  • ########################

  • 2 (## Part) –

  • 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.

  • either (# for parcel size use) –

  • 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.

  • attribute (# with constant or) –

  • transparency (can set parcel) –

  • 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.

  • creation. (**kwargs Anything else to pass to figure) –

Returns:

Figure object.

Return type:

fig