cytoflow.views.base_views#
Base classes for views.
I found, as I wrote a bunch of views, that I was also writing a bunch of shared boiler-plate code. This led to more bugs and a harder-to-maintain codebase. So, I extracted the copied code in a short hierarchy of reusable base classes:
BaseView – implements a view with row, column and hue facets.
After setting up the facet grid, it calls the derived class’s
_grid_plot to actually do the plotting. BaseView.plot also
has parameters to set the plot style, legend, axis labels, etc.
BaseDataView – implements a view that plots an Experiment’s
data (as opposed to a statistic.) Includes functionality for subsetting
the data before plotting, and determining axis limits and scales.
Base1DView – implements a 1-dimensional data view. See
HistogramView for an example.
Base2DView – implements a 2-dimensional data view. See
ScatterplotView for an example.
BaseNDView – implements an N-dimensional data view. See
RadvizView for an example.
BaseStatisticsView – implements a view that plots a statistic from
an Experiment (as opposed to the underlying data.) These views
have a “primary” BaseStatisticsView.statistic, and can be subset
as well.
Base1DStatisticsView – implements a view that plots one dimension
of a statistic. See BarChartView for an example.
Base2DStatisticsView – implements a view that plots two dimensions
of a statistic. See Stats2DView for an example.
- class cytoflow.views.base_views.BaseView[source]#
Bases:
HasStrictTraitsThe base class for facetted plotting.
- xfacet#
Set to one of the
Experiment.conditionsin theExperiment, and a new column of subplots will be added for every unique value of that condition.- Type:
String
- yfacet#
Set to one of the
Experiment.conditionsin theExperiment, and a new row of subplots will be added for every unique value of that condition.- Type:
String
- huefacet#
Set to one of the
Experiment.conditionsin the in theExperiment, and a new color will be added to the plot for every unique value of that condition.- Type:
String
- plot(experiment, data, **kwargs)[source]#
Base function for facetted plotting
- Parameters:
experiment (Experiment) – The
Experimentto plot using this view.title (str) – Set the plot title
xlabel (str) – Set the X axis label
ylabel (str) – Set the Y axis label
huelabel (str) – Set the label for the hue facet (in the legend)
legend (bool) – Plot a legend for the color or hue facet? Defaults to
True.legend_out (bool) – Plot the legend outside of the plot or grid? Defaults to
True.sharex (bool) – If there are multiple subplots, should they share X axes? Defaults to
True.sharey (bool) – If there are multiple subplots, should they share Y axes? Defaults to
True.row_order (list) – Override the row facet value order with the given list. If a value is not given in the ordering, it is not plotted. Defaults to a “natural ordering” of all the values.
col_order (list) – Override the column facet value order with the given list. If a value is not given in the ordering, it is not plotted. Defaults to a “natural ordering” of all the values.
hue_order (list) – Override the hue facet value order with the given list. If a value is not given in the ordering, it is not plotted. Defaults to a “natural ordering” of all the values.
height (float) – The height of each row in inches. Default = 3.0
aspect (float) – The aspect ratio of each subplot. Default = 1.5
col_wrap (int) – If
xfacetis set andyfacetis not set, you can “wrap” the subplots around so that they form a multi-row grid by setting this to the number of columns you want.sns_style ({“darkgrid”, “whitegrid”, “dark”, “white”, “ticks”}) – Which
seabornstyle to apply to the plot? Default iswhitegrid.sns_context ({“notebook”, “paper”, “talk”, “poster”}) – Which
seaborncontext to use? Controls the scaling of plot elements such as tick labels and the legend. Default isnotebook.palette (palette name, list, or dict) – Colors to use for the different levels of the hue variable. Should be something that can be interpreted by
seaborn.color_palette, or a dictionary mapping hue levels to matplotlib colors. See https://seaborn.pydata.org/tutorial/color_palettes.html for a good overview.despine (Bool) – Remove the top and right axes from the plot? Default is
True.
- class cytoflow.views.base_views.BaseDataView[source]#
Bases:
BaseViewThe base class for data views (as opposed to statistics views).
- subset#
An expression that specifies the subset of the statistic to plot. Passed unmodified to
pandas.DataFrame.query.- Type:
- plot(experiment, **kwargs)[source]#
Plot some data from an experiment. This function takes care of checking for facet name validity and subsetting, then passes the underlying dataframe to
BaseView.plot- Parameters:
min_quantile (float (>0.0 and <1.0, default = 0.001)) – Clip data that is less than this quantile.
max_quantile (float (>0.0 and <1.0, default = 1.00)) – Clip data that is greater than this quantile.
- Other Parameters:
lim (Dict(Str : (float, float))) – Set the range of each channel’s axis. If unspecified, assume that the limits are the minimum and maximum of the clipped data. Required.
scale (Dict(Str : IScale)) – Scale the data on each axis. Required.
- class cytoflow.views.base_views.Base1DView[source]#
Bases:
BaseDataViewA data view that plots data from a single channel.
- channel#
The channel to view
- Type:
Str
- scale#
The scale applied to the data before plotting it.
- Type:
{‘linear’, ‘log’, ‘logicle’}
- class cytoflow.views.base_views.Base2DView[source]#
Bases:
BaseDataViewA data view that plots data from two channels.
- xchannel#
The channel to view on the X axis
- Type:
Str
- ychannel#
The channel to view on the Y axis
- Type:
Str
- xscale#
The scales applied to the
xchanneldata before plotting it.- Type:
{‘linear’, ‘log’, ‘logicle’} (default = ‘linear’)
- class cytoflow.views.base_views.BaseNDView[source]#
Bases:
BaseDataViewA data view that plots data from one or more channels.
- channels#
The channels to view
- Type:
List(Str)
- scale#
Re-scale the data in the specified channels before plotting. If a channel isn’t specified, assume that the scale is linear.
- Type:
Dict(Str : {“linear”, “logicle”, “log”})
- class cytoflow.views.base_views.BaseStatisticsView[source]#
Bases:
BaseViewThe base class for statistics views (as opposed to data views).
- 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
- huefacet#
Set to one of the index levels in the statistic being plotted, and a new colored artist (line, bar, etc) will be added for every unique value of that index level.
- Type:
String
- subset#
An expression that specifies the subset of the statistic to plot. Passed unmodified to
pandas.DataFrame.query.- Type:
- enum_plots(experiment)[source]#
Enumerate the named plots we can make from this set of statistics.
- Returns:
An iterator across the possible plot names. The iterator ALSO has an instance attribute called
by, which holds a list of the facets that are not yet set (and thus need to be specified in the plot name.)- Return type:
iterator
- plot(experiment, plot_name=None, **kwargs)[source]#
Plot some data from a statistic.
This function takes care of checking for facet name validity and subsetting, then passes the dataframe to
BaseView.plot- Parameters:
plot_name (str) – If this
IViewcan make multiple plots,plot_nameis the name of the plot to make. Must be one of the values retrieved fromenum_plots.
- class cytoflow.views.base_views.Base1DStatisticsView[source]#
Bases:
BaseStatisticsViewThe base class for 1-dimensional statistic views – ie, the
variableattribute is on the x axis, and the statistic value is on the y axis.- variable#
The condition that varies when plotting this statistic: used for the x axis of line plots, the bar groups in bar plots, etc. Must be a level in the statistic’s index.
- Type:
Str
- feature#
The column in the statistic to plot (often a channel name.)
- Type:
Str
- error_low#
The name of the column used to plot low extent error bars. If
error_lowis set,error_highmust be set as well.- Type:
Str
- error_high#
The name of the column used to plot high extent error bars. If
error_highis set,error_lowmust be set as well.- Type:
Str
- scale#
The scale applied to the data before plotting it.
- Type:
{‘linear’, ‘log’, ‘logicle’}
- class cytoflow.views.base_views.Base2DStatisticsView[source]#
Bases:
BaseStatisticsViewThe base class for 2-dimensional statistic views – ie, the
variableattribute varies independently, and the corresponding values from the x and y statistics are plotted on the x and y axes.- variable#
The condition that varies when plotting this statistic: used for the x axis of line plots, the bar groups in bar plots, etc. Must be a level in the statistic’s index.
- Type:
Str
- xfeature#
The name of the column to plot on the X axis.
- Type:
Str
- xerror_low#
The name of the column containing the low values for the X error bars. If
xerror_lowis set,xerror_highmust be set as well.- Type:
Str
- xerror_high#
The name of the column containing the high values for the X error bars. If
xerror_highis set,xerror_lowmust be set as well.- Type:
Str
- yfeature#
The name of the column to plot on the Y axis.
- Type:
Str
- yerror_low#
The name of the column containing the low values for the Y error bars. If
yerror_lowis set,yerror_highmust be set as well.- Type:
Str
- yerror_high#
The name of the column containing the high values for the Y error bars. If
yerror_highis set,yerror_lowmust be set as well.- Type:
Str
- xscale#
The scale applied to X axis.
- Type:
{‘linear’, ‘log’, ‘logicle’}
- yscale#
The scale applied to Y axis.
- Type:
{‘linear’, ‘log’, ‘logicle’}