# Plotting¶

## Heatmap¶

graspy.plot.heatmap(X, transform=None, figsize=(10, 10), title=None, context='talk', font_scale=1, xticklabels=False, yticklabels=False, cmap='RdBu_r', vmin=None, vmax=None, center=0, cbar=True, inner_hier_labels=None, outer_hier_labels=None, hier_label_fontsize=30, ax=None, title_pad=None, sort_nodes=False)[source]

Plots a graph as a color-encoded matrix.

Nodes can be grouped by providing inner_hier_labels or both inner_hier_labels and outer_hier_labels. Nodes can also be sorted by the degree from largest to smallest degree nodes. The nodes will be sorted within each group if labels are also provided.

Read more in the tutorials

Parameters: X : nx.Graph or np.ndarray object Graph or numpy matrix to plot transform : None, or string {'log', 'log10', 'zero-boost', 'simple-all', 'simple-nonzero'} 'log' : Plots the natural log of all nonzero numbers 'log10' : Plots the base 10 log of all nonzero numbers 'zero-boost' : Pass to ranks method. preserves the edge weight for all 0s, but ranks the other edges as if the ranks of all 0 edges has been assigned. 'simple-all': Pass to ranks method. Assigns ranks to all non-zero edges, settling ties using the average. Ranks are then scaled by $$\frac{rank(\text{non-zero edges})}{n^2 + 1}$$ where n is the number of nodes 'simple-nonzero': Pass to ranks method. Same as simple-all, but ranks are scaled by $$\frac{rank(\text{non-zero edges})}{\text{# non-zero edges} + 1}$$ 'binarize': Binarize input graph such that any edge weight greater than 0 becomes 1. figsize : tuple of integers, optional, default: (10, 10) Width, height in inches. title : str, optional, default: None Title of plot. context : None, or one of {paper, notebook, talk (default), poster} The name of a preconfigured set. font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. xticklabels, yticklabels : bool or list, optional If list-like, plot these alternate labels as the ticklabels. cmap : str, list of colors, or matplotlib.colors.Colormap, default: 'RdBu_r' Valid matplotlib color map. vmin, vmax : floats, optional (default=None) Values to anchor the colormap, otherwise they are inferred from the data and other keyword arguments. center : float, default: 0 The value at which to center the colormap cbar : bool, default: True Whether to draw a colorbar. inner_hier_labels : array-like, length of X's first dimension, default: None Categorical labeling of the nodes. If not None, will group the nodes according to these labels and plot the labels on the marginal outer_hier_labels : array-like, length of X's first dimension, default: None Categorical labeling of the nodes, ignored without inner_hier_labels If not None, will plot these labels as the second level of a hierarchy on the marginals hier_label_fontsize : int Size (in points) of the text labels for the inner_hier_labels and outer_hier_labels. ax : matplotlib Axes, optional Axes in which to draw the plot, otherwise will generate its own axes title_pad : int, float or None, optional (default=None) Custom padding to use for the distance of the title from the heatmap. Autoscales if None sort_nodes : boolean, optional (default=False) Whether or not to sort the nodes of the graph by the sum of edge weights (degree for an unweighted graph). If inner_hier_labels is passed and sort_nodes is True, will sort nodes this way within block.

## Gridplot¶

graspy.plot.gridplot(X, labels=None, transform=None, height=10, title=None, context='talk', font_scale=1, alpha=0.7, sizes=(10, 200), palette='Set1', legend_name='Type', inner_hier_labels=None, outer_hier_labels=None, hier_label_fontsize=30, title_pad=None, sort_nodes=False)[source]

Plots multiple graphs on top of each other with dots as edges.

This function is useful for visualizing multiple graphs simultaneously. The size of the dots correspond to the edge weights of the graphs, and colors represent input graphs.

Read more in the tutorials

Parameters: X : list of nx.Graph or np.ndarray object List of nx.Graph or numpy arrays to plot labels : list of str List of strings, which are labels for each element in X. len(X) == len(labels). transform : None, or string {'log', 'log10', 'zero-boost', 'simple-all', 'simple-nonzero'} 'log' : Plots the natural log of all nonzero numbers 'log10' : Plots the base 10 log of all nonzero numbers 'zero-boost' : Pass to ranks method. preserves the edge weight for all 0s, but ranks the other edges as if the ranks of all 0 edges has been assigned. 'simple-all': Pass to ranks method. Assigns ranks to all non-zero edges, settling ties using the average. Ranks are then scaled by $$\frac{rank(\text{non-zero edges})}{n^2 + 1}$$ where n is the number of nodes 'simple-nonzero': Pass to ranks method. Same as simple-all, but ranks are scaled by $$\frac{rank(\text{non-zero edges})}{\text{# non-zero edges} + 1}$$ 'binarize': Binarize input graph such that any edge weight greater than 0 becomes 1. height : int, optional, default: 10 Height of figure in inches. title : str, optional, default: None Title of plot. context : None, or one of {paper, notebook, talk (default), poster} The name of a preconfigured set. font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. palette : str, dict, optional, default: 'Set1' Set of colors for mapping the hue variable. If a dict, keys should be values in the hue variable alpha : float [0, 1], default Alpha value of plotted gridplot points sizes : length 2 tuple, default: (10, 200) Min and max size to plot edge weights legend_name : string, default: 'Type' Name to plot above the legend inner_hier_labels : array-like, length of X's first dimension, default: None Categorical labeling of the nodes. If not None, will group the nodes according to these labels and plot the labels on the marginal outer_hier_labels : array-like, length of X's first dimension, default: None Categorical labeling of the nodes, ignored without inner_hier_labels If not None, will plot these labels as the second level of a hierarchy on the marginals hier_label_fontsize : int Size (in points) of the text labels for the inner_hier_labels and outer_hier_labels. title_pad : int, float or None, optional (default=None) Custom padding to use for the distance of the title from the heatmap. Autoscales if None sort_nodes : boolean, optional (default=False) Whether or not to sort the nodes of the graph by the sum of edge weights (degree for an unweighted graph). If inner_hier_labels is passed and sort_nodes is True, will sort nodes this way within block.

## Pairplot¶

graspy.plot.pairplot(X, labels=None, col_names=None, title=None, legend_name=None, variables=None, height=2.5, context='talk', font_scale=1, palette='Set1', alpha=0.7, size=50, marker='.', diag_kind='auto')[source]

Plot pairwise relationships in a dataset.

By default, this function will create a grid of Axes such that each dimension in data will by shared in the y-axis across a single row and in the x-axis across a single column.

The off-diagonal Axes show the pairwise relationships displayed as scatterplot. The diagonal Axes show the univariate distribution of the data for that dimension displayed as either a histogram or kernel density estimates (KDEs).

Read more in the tutorials

Parameters: X : array-like, shape (n_samples, n_features) Input data. labels : array-like or list, shape (n_samples), optional Labels that correspond to each sample in X. col_names : array-like or list, shape (n_features), optional Names or labels for each feature in X. If not provided, the default will be Dimension 1, Dimension 2, etc. title : str, optional, default: None Title of plot. legend_name : str, optional, default: None Title of the legend. variables : list of variable names, optional Variables to plot based on col_names, otherwise use every column with a numeric datatype. height : int, optional, default: 10 Height of figure in inches. context : None, or one of {paper, notebook, talk (default), poster} The name of a preconfigured set. font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. palette : str, dict, optional, default: 'Set1' Set of colors for mapping the hue variable. If a dict, keys should be values in the hue variable. alpha : float, optional, default: 0.7 Opacity value of plotter markers between 0 and 1 size : float or int, optional, default: 50 Size of plotted markers marker : string, optional, default: '.' Matplotlib style marker specification https://matplotlib.org/api/markers_api.html

## Degreeplot¶

graspy.plot.degreeplot(X, labels=None, direction='out', title='Degree plot', context='talk', font_scale=1, figsize=(10, 5), palette='Set1')[source]

Plots the distribution of node degrees for the input graph. Allows for sets of node labels, will plot a distribution for each node category.

Parameters: X : np.ndarray (2D) input graph labels : 1d np.ndarray or list, same length as dimensions of X Labels for different categories of graph nodes direction : string, ('out', 'in') Whether to plot out degree or in degree for a directed graph title : string, default Plot title context : None, or one of {talk (default), paper, notebook, poster} Seaborn plotting context font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. palette : str, dict, optional, default: 'Set1' Set of colors for mapping the hue variable. If a dict, keys should be values in the hue variable. figsize : tuple of length 2, default (10, 5) Size of the figure (width, height) ax : matplotlib axis object

## Edgeplot¶

graspy.plot.edgeplot(X, labels=None, nonzero=False, title='Edge plot', context='talk', font_scale=1, figsize=(10, 5), palette='Set1')[source]

Plots the distribution of edge weights for the input graph. Allows for sets of node labels, will plot edge weight distribution for each node category.

Parameters: X : np.ndarray (2D) Input graph labels : 1d np.ndarray or list, same length as dimensions of X Labels for different categories of graph nodes nonzero : boolean, default: False Whether to restrict the edgeplot to only the non-zero edges title : string, default Plot title context : None, or one of {talk (default), paper, notebook, poster} Seaborn plotting context font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. palette : str, dict, optional, default: 'Set1' Set of colors for mapping the hue variable. If a dict, keys should be values in the hue variable. figsize : tuple of length 2, default (10, 5) Size of the figure (width, height) ax : matplotlib axis object

## Screeplot¶

graspy.plot.screeplot(X, title='Scree plot', context='talk', font_scale=1, figsize=(10, 5), cumulative=True, show_first=None)[source]

Plots the distribution of singular values for a matrix, either showing the raw distribution or an empirical CDF (depending on cumulative)

Parameters: X : np.ndarray (2D) Input matrix title : string, default Plot title context : None, or one of {talk (default), paper, notebook, poster} Seaborn plotting context font_scale : float, optional, default: 1 Separate scaling factor to independently scale the size of the font elements. figsize : tuple of length 2, default (10, 5) Size of the figure (width, height) cumulative : boolean, default: True Whether or not to plot a cumulative cdf of singular values show_first : int or None, default: None Whether to restrict the plot to the first show_first components ax : matplotlib axis object