plot_static_mapper_graph¶
-
gtda.mapper.
plot_static_mapper_graph
(pipeline, data, layout='kamada_kawai', layout_dim=2, color_variable=None, node_color_statistic=None, color_by_columns_dropdown=False, clone_pipeline=True, n_sig_figs=3, node_scale=12, plotly_params=None)[source]¶ Plot Mapper graphs without interactivity on pipeline parameters.
The output graph is a rendition of the
igraph.Graph
object computed by calling thefit_transform
method of theMapperPipeline
instance pipeline on the input data. The graph’s nodes correspond to subsets of elements (rows) in data; these subsets are clusters in larger portions of data called “pullback (cover) sets”, which are computed by means of the pipeline’s “filter function” and “cover” and correspond to the differently-colored portions in this diagram. Two clusters from different pullback cover sets can overlap; if they do, an edge between the corresponding nodes in the graph may be drawn.Nodes are colored according to color_variable and node_color_statistic and are sized according to the number of elements they represent. The hovertext on each node displays, in this order:
a globally unique ID for the node, which can be used to retrieve node information from the
igraph.Graph
object, seeNerve
;the label of the pullback (cover) set which the node’s elements form a cluster in;
a label identifying the node as a cluster within that pullback set;
the number of elements of data associated with the node;
the value of the summary statistic which determines the node’s color.
- Parameters
pipeline (
MapperPipeline
object) – Mapper pipeline to act onto data.data (array-like of shape (n_samples, n_features)) – Data used to generate the Mapper graph. Can be a pandas dataframe.
layout (None, str or callable, optional, default:
"kamada-kawai"
) – Layout algorithm for the graph. Can be any accepted value for thelayout
parameter in thelayout
method ofigraph.Graph
1.layout_dim (int, default:
2
) – The number of dimensions for the layout. Can be 2 or 3.color_variable (object or None, optional, default:
None
) –Specifies a feature of interest to be used, together with node_color_statistic, to determine node colors.
If a numpy array or pandas dataframe, it must have the same length as data.
None
is equivalent to passing data.If an object implementing
transform
orfit_transform
, it is applied to data to generate the feature of interest.If an index or string, or list of indices/strings, it is equivalent to selecting a column or subset of columns from data.
node_color_statistic (None, callable, or ndarray of shape (n_nodes,) or (n_nodes, 1), optional, default:
None
) – If a callable, node colors will be computed as summary statistics from the feature arrayY
determined by color_variable – specifically, the color of a node representing the entries of data whose row indices are inI
will benode_color_statistic(Y[I])
.None
is equivalent to passingnumpy.mean
. If a numpy array, it must have the same length as the number of nodes in the Mapper graph and its values are used directly as node colors (color_variable is ignored).color_by_columns_dropdown (bool, optional, default:
False
) – IfTrue
, a dropdown widget is generated which allows the user to color Mapper nodes according to any column in data (still using node_color_statistic) in addition to color_variable.clone_pipeline (bool, optional, default:
True
) – IfTrue
, the input pipeline is cloned before computing the Mapper graph to prevent unexpected side effects from in-place parameter updates.n_sig_figs (int or None, optional, default:
3
) – If notNone
, number of significant figures to which to round node summary statistics. IfNone
, no rounding is performed.node_scale (int or float, optional, default:
12
) – Sets the scale factor used to determine the rendered size of the nodes. Increase for larger nodes. Implements a formula in the Plotly documentation.plotly_params (dict or None, optional, default:
None
) – Custom parameters to configure the plotly figure. Allowed keys are"node_trace"
,"edge_trace"
and"layout"
, and the corresponding values should be dictionaries containing keyword arguments as would be fed to theupdate_traces
andupdate_layout
methods ofplotly.graph_objects.Figure
.
- Returns
fig – Figure representing the Mapper graph with appropriate node colouring and size.
- Return type
plotly.graph_objects.Figure
object
Examples
Setting a colorscale different from the default one:
>>> import numpy as np >>> np.random.seed(1) >>> from gtda.mapper import make_mapper_pipeline, plot_static_mapper_graph >>> pipeline = make_mapper_pipeline() >>> data = np.random.random((100, 3)) >>> plotly_params = {"node_trace": {"marker_colorscale": "Blues"}} >>> fig = plot_static_mapper_graph(pipeline, data, ... plotly_params=plotly_params)
Inspect the composition of a node with “Node ID” displayed as 0 in the hovertext:
>>> graph = pipeline.fit_transform(data) >>> graph.vs[0]["node_elements"] array([70])
References
- 1
igraph.Graph.layout documentation.