Plotting

The pygsp.plotting module implements functionality to plot PyGSP objects with a pyqtgraph or matplotlib drawing backend (which can be controlled by the BACKEND constant or individually for each plotting call):

pygsp.plotting.BACKEND

Indicates which drawing backend to use if none are provided to the plotting functions. Should be either ‘matplotlib’ or ‘pyqtgraph’. In general pyqtgraph is better for interactive exploration while matplotlib is better at generating figures to be included in papers or elsewhere.

pygsp.plotting.close(*args, **kwargs)[source]

Close created figures.

Alias to plt.close().

pygsp.plotting.close_all()[source]

Close all opened windows.

pygsp.plotting.plot(O, **kwargs)[source]

Main plotting function.

This convenience function either calls plot_graph() or plot_filter() given the type of the passed object. Parameters can be passed to those functions.

Parameters:

O : Graph, Filter

object to plot

Examples

>>> from pygsp import plotting
>>> G = graphs.Logo()
>>> plotting.plot(G)
pygsp.plotting.plot_filter(obj, *args, **kwargs)[source]
pygsp.plotting.plot_graph(G, backend=None, **kwargs)[source]

Plot a graph or a list of graphs.

Parameters:

G : Graph

Graph to plot.

show_edges : bool

True to draw edges, false to only draw vertices. Default True if less than 10,000 edges to draw. Note that drawing a large number of edges might be particularly slow.

backend: {‘matplotlib’, ‘pyqtgraph’}

Defines the drawing backend to use. Defaults to BACKEND.

vertex_size : float

Size of circle representing each node.

plot_name : str

name of the plot

save_as : str

Whether to save the plot as save_as.png and save_as.pdf. Shown in a window if None (default). Only available with the matplotlib backend.

ax : matplotlib.axes

Axes where to draw the graph. Optional, created if not passed. Only available with the matplotlib backend.

Examples

>>> from pygsp import plotting
>>> G = graphs.Logo()
>>> plotting.plot_graph(G)
pygsp.plotting.plot_signal(G, signal, backend=None, **kwargs)[source]

Plot a signal on top of a graph.

Parameters:

G : Graph

Graph to plot a signal on top.

signal : array of int

Signal to plot. Signal length should be equal to the number of nodes.

show_edges : bool

True to draw edges, false to only draw vertices. Default True if less than 10,000 edges to draw. Note that drawing a large number of edges might be particularly slow.

cp : list of int

NOT IMPLEMENTED. Camera position when plotting a 3D graph.

vertex_size : float

Size of circle representing each node.

highlight : iterable

List of indices of vertices to be highlighted. Useful to e.g. show where a filter was localized. Only available with the matplotlib backend.

colorbar : bool

Whether to plot a colorbar indicating the signal’s amplitude. Only available with the matplotlib backend.

limits : [vmin, vmax]

Maps colors from vmin to vmax. Defaults to signal minimum and maximum value. Only available with the matplotlib backend.

bar : boolean

NOT IMPLEMENTED. Signal values are displayed using colors when False, and bars when True (default False).

bar_width : int

NOT IMPLEMENTED. Width of the bar (default 1).

backend: {‘matplotlib’, ‘pyqtgraph’}

Defines the drawing backend to use. Defaults to BACKEND.

plot_name : string

Name of the plot.

save_as : str

Whether to save the plot as save_as.png and save_as.pdf. Shown in a window if None (default). Only available with the matplotlib backend.

ax : matplotlib.axes

Axes where to draw the graph. Optional, created if not passed. Only available with the matplotlib backend.

Examples

>>> from pygsp import plotting
>>> G = graphs.Grid2d(4)
>>> signal = np.sin((np.arange(16) * 2*np.pi/16))
>>> plotting.plot_signal(G, signal)
pygsp.plotting.plot_spectrogram(G, node_idx=None)[source]

Plot the spectrogram of the given graph.

Parameters:

G : Graph

Graph to analyse.

node_idx : ndarray

Order to sort the nodes in the spectrogram

Examples

>>> from pygsp import plotting
>>> G = graphs.Ring(15)
>>> plotting.plot_spectrogram(G)
pygsp.plotting.show(*args, **kwargs)[source]

Show created figures.

Alias to plt.show(). By default, showing plots does not block the prompt.