cytoflow.views.matrix#

Plots a “matrix” view – a 2D representation of a heat map, pie plots, or petal plots.

MatrixView – plots the matrix view.

class cytoflow.views.matrix.MatrixView[source]#

Bases: HasStrictTraits

A view that creates a matrix view (a 2D grid representation) of a statistic. Set statistic to the name of the statistic to plot; set feature to the name of that statistic’s feature you’d like to analyze.

Setting xfacet and yfacet to levels of the statistic’s index will result in a separate column or row for each value of that statistic.

There are three different ways of plotting the values of the matrix view (the “cells” in the matrix), controlled by the type parameter:

  • Setting style to heat (the default) will produce a “traditional” heat map, where each “cell” is a circle and the color of the circle is related to the intensity of the value of feature. (In this scenario, variable is ignored.)

  • Setting style to pie will draw a pie plot in each cell. If variable is set, then the values of variable are used as the categories of the pie, and the arc length of each slice of pie is related to the intensity of the value of feature. If variable is not set, however, feature is ignored and the features of the statistic become the categories. In this case, all of the statistic index levels must be either used in the view facets or specified in the plot_name parameter of plot.

  • Setting style to petal will draw a “petal plot” in each cell. If variable is set, then the values of variable are used as the categories, but unlike a pie plot, the arc width of each slice is equal. Instead, the radius of the pie slice scales with the square root of the intensity, so that the relationship between area and intensity remains the same. If variable is not set, however, feature is ignored and the features of the statistic become the categories. In this case, all of the statistic index levels must be either used in the view facets or set in the plot_name parameter of plot

Warning

If style is pie or petal, then negative data will be clipped to 0!

Optionally, you can set size_function to scale the circles (or pies or petals) by a function computed on Experiment.data. (Often set to len to scale by the number of events in each subset.)

statistic#

The statistic to plot. Must be a key in Experiment.statistics.

Type:

Str

xfacet#

Set to one of the index levels in the statistic being plotted, and a new column of subplots will be added for every unique value of that index level.

Type:

String

yfacet#

Set to one of the index levels in the statistic being plotted, and a new row of subplots will be added for every unique value of that index level.

Type:

String

variable#

The variable (index level) used for plotting pie and petal plots. Ignored for a heatmap. If unset, use the statistic features as categories.

Type:

Str

feature#

The column in the statistic to plot (often a channel name.) Ignored if variable is left unset.

Type:

Str

style#

What kind of matrix plot to make?

Type:

Enum(heat, pie, petal) (default = heat)

scale#

For a heat map, how should the color of feature be scaled before plotting? If style is not heat, scale must be linear.

Type:

Enum(linear, log, logicle} (default = linear)

size_function#

If set, separate the Experiment into subsets by xfacet and yfacet (which should be conditions in the Experiment), compute a function on them, and scale the size of each matrix cell by those values. The callable should take a single pandas.DataFrame argument and return a positive float or value that can be cast to float (such as int). Of particular use is len, which will scale the cells by the number of events in each subset.

Type:

Callable

subset#

Only plot a subset of the data in statistic. Passed directly to pandas.DataFrame.query.

Type:

Str

Note

MatrixView implements the IView interface, but it is NOT a subclass BaseStatisticsView. This is because MatrixView does not use seaborn.FacetGrid to lay out the subplots – all the layout logic imposes a huge overhead cost. Instead MatrixView uses classes from mpl_toolkits.axes_grid1 for its layout.

Examples

Make a little data set.

>>> import cytoflow as flow
>>> import_op = flow.ImportOp()
>>> import_op.tubes = [flow.Tube(file = "Plate01/RFP_Well_A3.fcs",
...                              conditions = {'Dox' : 10.0}),
...                    flow.Tube(file = "Plate01/CFP_Well_A4.fcs",
...                              conditions = {'Dox' : 1.0})]
>>> import_op.conditions = {'Dox' : 'float'}
>>> ex = import_op.apply()

Add a threshold gate

>>> ex2 = flow.ThresholdOp(name = 'Threshold',
...                        channel = 'Y2-A',
...                        threshold = 2000).apply(ex)

Add a statistic

>>> ex3 = flow.ChannelStatisticOp(name = "ByDox",
...                               channel = "Y2-A",
...                               by = ['Dox', 'Threshold'],
...                               function = len).apply(ex2)

Plot the bar chart

>>> flow.MatrixView(statistic = "ByDox",
...                 xfacet = 'Dox',
...                 variable = 'Threshold',
...                 feature = 'Y2-A',
...                 style = 'pie').plot(ex3)
../../_images/cytoflow-views-matrix-4.png
plot(experiment, plot_name=None, **kwargs)[source]#

Plot a chart of a variable’s values against a statistic.

Parameters:
  • experiment (Experiment) – The Experiment to plot using this view.

  • plot_name (str) – If this IView can make multiple plots, plot_name is the name of the plot to make. Must be one of the values retrieved from enum_plots.

  • title (str) – Set the plot title

  • xlabel (str) – Set the X axis label

  • ylabel (str) – Set the Y axis label

  • legend (bool) – Plot a legend or color bar? Defaults to True.

  • legendlabel (str) – Set the label for the color bar or legend

  • palette (palette name) – Colors to use for the different levels of the hue variable. Should be something that can be interpreted by seaborn.color_palette. If plotting a heat map, this should be a continuous color map (‘viridis’ is the default.) Otherwise, choose either a discrete color map (‘deep’ is the default) or a continuous color map from which equi-spaced colors will be drawn.

  • All other parameters are passed to the ``wedgeprops`` argument of

  • `matplotlib.axes.Axes.pie` – ie, they should be matplotlib patch

  • properties.

enum_plots(experiment)[source]#