OrdinationResults.
plot
(df=None, column=None, axes=(0, 1, 2), axis_labels=None, title='', cmap=None, s=20)[source]¶Create a 3-D scatterplot of ordination results colored by metadata.
State: Experimental as of 0.4.0.
Creates a 3-D scatterplot of the ordination results, where each point represents a sample. Optionally, these points can be colored by metadata (see df and column below).
Parameters: | df : pd.DataFrame, optional
column : str, optional
axes : iterable of int, optional
axis_labels : iterable of str, optional
title : str, optional
cmap : str or matplotlib.colors.Colormap, optional
s : scalar or iterable of scalars, optional
|
---|---|
Returns: | matplotlib.figure.Figure
|
Raises: | ValueError
|
See also
mpl_toolkits.mplot3d.Axes3D.scatter
Notes
This method creates basic plots of ordination results, and is intended to provide a quick look at the results in the context of metadata (e.g., from within the IPython Notebook). For more customization and to generate publication-quality figures, we recommend EMPeror [R170170].
References
[R169170] | (1, 2) http://matplotlib.org/examples/color/colormaps_reference.html |
[R170170] | (1, 2) EMPeror: a tool for visualizing high-throughput microbial community data. Vazquez-Baeza Y, Pirrung M, Gonzalez A, Knight R. Gigascience. 2013 Nov 26;2(1):16. http://biocore.github.io/emperor/ |
Examples
Define a distance matrix with four samples labelled A-D:
>>> from skbio import DistanceMatrix
>>> dm = DistanceMatrix([[0., 0.21712454, 0.5007512, 0.91769271],
... [0.21712454, 0., 0.45995501, 0.80332382],
... [0.5007512, 0.45995501, 0., 0.65463348],
... [0.91769271, 0.80332382, 0.65463348, 0.]],
... ['A', 'B', 'C', 'D'])
Define metadata for each sample in a pandas.DataFrame
:
>>> import pandas as pd
>>> metadata = {
... 'A': {'body_site': 'skin'},
... 'B': {'body_site': 'gut'},
... 'C': {'body_site': 'gut'},
... 'D': {'body_site': 'skin'}}
>>> df = pd.DataFrame.from_dict(metadata, orient='index')
Run principal coordinate analysis (PCoA) on the distance matrix:
>>> from skbio.stats.ordination import pcoa
>>> pcoa_results = pcoa(dm)
Plot the ordination results, where each sample is colored by body site (a categorical variable):
>>> fig = pcoa_results.plot(df=df, column='body_site',
... title='Samples colored by body site',
... cmap='Set1', s=50)
(Source code, png)