hv_anndata.plotting.scanpy.matrixplot

hv_anndata.plotting.scanpy.matrixplot(adata, /, group_by, *, func='mean', data=A.X, add_totals=False)

Heatmap with totals per column.

Parameters:
adata AnnData

The AnnData object.

group_by AdDim

The groupby expression.

func Literal['count_nonzero', 'mean', 'sum', 'var', 'median'], default: 'mean'

The aggregation function.

data LayerAcc | MultiAcc, default: A.X

The data to plot.

add_totals bool, default: False

Whether to add totals per group.

Return type:

HeatMap | AdjointLayout

Returns:

A heatmap. If add_totals is True, a AdjointLayout is returned containing the heatmap and a Bars object.

Examples

import hv_anndata.plotting.scanpy as hv_sc
from hv_anndata import data, register, A

register()

adata = data.pbmc68k_processed()
markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"]
hv_sc.matrixplot(
    adata[:, markers], A.obs["bulk_labels"], data=A.layers["counts"],
    add_totals=True
)
import hv_anndata.plotting.scanpy as hv_sc
from hv_anndata import data, register, A

register()

adata = data.pbmc68k_processed()
markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"]
hv_sc.matrixplot(
    adata[:, markers], A.obs["bulk_labels"], data=A.layers["counts"],
    add_totals=True
)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
import hv_anndata.plotting.scanpy as hv_sc
from hv_anndata import data, register, A

register()

adata = data.pbmc68k_processed()
markers = ["C1QA", "PSAP", "CD79A", "CD79B", "CST3", "LYZ"]
hv_sc.matrixplot(
    adata[:, markers], A.obs["bulk_labels"], data=A.layers["counts"],
    add_totals=True
)
/home/docs/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/__init__.py:664: FutureWarning: Probably comparing to a dimension created from `Dimension.name`. This will not be supported in the future, please report as an issue. 
  if dim in sel_dims or (isinstance(dim, int) and dim < ndims)
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/dimension.py:1381, in Dimensioned._repr_mimebundle_(self, include, exclude)
   1374 def _repr_mimebundle_(self, include=None, exclude=None):
   1375     """Resolves the class hierarchy for the class rendering the
   1376     object using any display hooks registered on Store.display
   1377     hooks.  The output of all registered display_hooks is then
   1378     combined and returned.
   1379 
   1380     """
-> 1381     return Store.render(self)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/options.py:1433, in Store.render(cls, obj)
   1431 data, metadata = {}, {}
   1432 for hook in hooks:
-> 1433     ret = hook(obj)
   1434     if ret is None:
   1435         continue

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/ipython/display_hooks.py:340, in pprint_display(obj)
    338 if not ip.display_formatter.formatters['text/plain'].pprint:
    339     return None
--> 340 return display(obj, raw_output=True)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/ipython/display_hooks.py:311, in display(obj, raw_output, **kwargs)
    309 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)):
    310     with option_state(obj):
--> 311         output = layout_display(obj)
    312 elif isinstance(obj, (HoloMap, DynamicMap)):
    313     with option_state(obj):

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/ipython/display_hooks.py:205, in display_hook.<locals>.wrapped(element)
    203 try:
    204     max_frames = OutputSettings.options['max_frames']
--> 205     mimebundle = fn(element, max_frames=max_frames)
    206     if mimebundle is None:
    207         return {}, {}

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/ipython/display_hooks.py:274, in layout_display(layout, max_frames)
    271     max_frame_warning(max_frames)
    272     return None
--> 274 return render(layout)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/ipython/display_hooks.py:76, in render(obj, **kwargs)
     73 if renderer.fig == 'pdf':
     74     renderer = renderer.instance(fig='png')
---> 76 return renderer.components(obj, **kwargs)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/renderer.py:396, in Renderer.components(self, obj, fmt, comm, **kwargs)
    394 embed = (not (dynamic or streams or self.widget_mode == 'live') or config.embed)
    395 if embed or config.comms == 'default':
--> 396     return self._render_panel(plot, embed, comm)
    397 return self._render_ipywidget(plot)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/renderer.py:403, in Renderer._render_panel(self, plot, embed, comm)
    401 doc = Document()
    402 with config.set(embed=embed):
--> 403     model = plot.layout._render_model(doc, comm)
    404 if embed:
    405     return render_model(model, comm)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/viewable.py:775, in Viewable._render_model(self, doc, comm)
    773 if comm is None:
    774     comm = state._comm_manager.get_server_comm()
--> 775 model = self.get_root(doc, comm)
    777 if self._design and self._design.theme.bokeh_theme:
    778     doc.theme = self._design.theme.bokeh_theme

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/layout/base.py:332, in Panel.get_root(self, doc, comm, preprocess)
    328 def get_root(
    329     self, doc: Document | None = None, comm: Comm | None = None,
    330     preprocess: bool = True
    331 ) -> Model:
--> 332     root = super().get_root(doc, comm, preprocess)
    333     # ALERT: Find a better way to handle this
    334     if hasattr(root, 'styles') and 'overflow-x' in root.styles:

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/viewable.py:705, in Renderable.get_root(self, doc, comm, preprocess)
    703 wrapper = self._design._wrapper(self)
    704 if wrapper is self:
--> 705     root = self._get_model(doc, comm=comm)
    706     if preprocess:
    707         self._preprocess(root)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/layout/base.py:316, in Panel._get_model(self, doc, root, parent, comm)
    314 root = root or model
    315 self._models[root.ref['id']] = (model, parent)
--> 316 objects, _ = self._get_objects(model, [], doc, root, comm)
    317 props = self._get_properties(doc)
    318 props[self._property_mapping['objects']] = objects

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/layout/base.py:298, in Panel._get_objects(self, model, old_objects, doc, root, comm)
    296 else:
    297     try:
--> 298         child = pane._get_model(doc, root, model, comm)
    299     except RerenderError as e:
    300         if e.layout is not None and e.layout is not self:

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/pane/holoviews.py:494, in HoloViews._get_model(self, doc, root, parent, comm)
    492     plot = self.object
    493 else:
--> 494     plot = self._render(doc, comm, root)
    496 plot.pane = self
    497 backend = plot.renderer.backend

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/panel/pane/holoviews.py:588, in HoloViews._render(self, doc, comm, root)
    585     if comm:
    586         kwargs['comm'] = comm
--> 588 return renderer.get_plot(self.object, **kwargs)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/renderer.py:239, in Renderer.get_plot(self_or_cls, obj, doc, renderer, comm, **kwargs)
    236     defaults = [kd.default for kd in plot.dimensions]
    237     init_key = tuple(v if d is None else d for v, d in
    238                      zip(plot.keys[0], defaults, strict=None))
--> 239     plot.update(init_key)
    240 else:
    241     plot = obj

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plot.py:958, in DimensionedPlot.update(self, key)
    956 def update(self, key):
    957     if len(self) == 1 and key in (0, self.keys[0]) and not self.drawn:
--> 958         return self.initialize_plot()
    959     item = self.__getitem__(key)
    960     self.traverse(lambda x: setattr(x, '_updated', True))

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/plot.py:51, in PlotlyPlot.initialize_plot(self, ranges, is_geo)
     50 def initialize_plot(self, ranges=None, is_geo=False):
---> 51     return self.generate_plot(self.keys[-1], ranges, is_geo=is_geo)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/plot.py:206, in LayoutPlot.generate_plot(self, key, ranges, is_geo)
    204 subplot = self.subplots.get((r, c), None)
    205 if subplot is not None:
--> 206     subplots = subplot.generate_plot(key, ranges=ranges, is_geo=is_geo)
    208     # Computes plotting offsets depending on
    209     # number of adjoined plots
    210     offset = sum(r >= ir for ir in insert_rows)

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/plot.py:276, in AdjointLayoutPlot.generate_plot(self, key, ranges, is_geo)
    273     # If no view object or empty position, disable the axis
    274     if subplot:
    275         adjoined_plots.append(
--> 276             subplot.generate_plot(key, ranges=ranges, is_geo=is_geo)
    277         )
    278 if not adjoined_plots: adjoined_plots = [None]
    279 return adjoined_plots

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/element.py:185, in ElementPlot.generate_plot(self, key, ranges, element, is_geo)
    179         raise ValueError(
    180             f"The following {type(element).__name__} style options are not supported by the Plotly "
    181             f"backend when overlaid on Tiles:\n    {unsupported_opts}"
    182         )
    184 # Get data and options and merge them
--> 185 data = self.get_data(element, ranges, style, is_geo=is_geo)
    186 opts = self.graph_options(element, ranges, style, is_geo=is_geo)
    188 components = {
    189     'traces': [],
    190     'images': [],
    191     'annotations': [],
    192     'shapes': [],
    193 }

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/chart.py:255, in BarPlot.get_data(self, element, ranges, style, **kwargs)
    253     for v in xvals:
    254         sel = element[[v]]
--> 255         values.append(sel.iloc[0, 1] if len(sel) else 0)
    256     bars.append({
    257         'orientation': orientation, 'showlegend': False,
    258         x: xvals,
    259         y: np.nan_to_num(values)})
    260 elif stack_dim or not self.multi_level:

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/interface.py:36, in Accessor.__getitem__(self, index)
     34     self.dataset._in_method = True
     35 try:
---> 36     res = self._perform_getitem(self.dataset, index)
     37     if not in_method and isinstance(res, Dataset):
     38         getitem_op = method.instance(
     39             input_type=type(self),
     40             output_type=type(self.dataset),
     41             method_name='_perform_getitem',
     42             args=[index],
     43         )

File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/core/data/interface.py:80, in iloc._perform_getitem(cls, dataset, index)
     77 if rows is Ellipsis:
     78     rows = slice(None)
---> 80 data = dataset.interface.iloc(dataset, (rows, cols))
     81 kdims = dataset.kdims
     82 vdims = dataset.vdims

File ~/checkouts/readthedocs.org/user_builds/hv-anndata/checkouts/latest/src/hv_anndata/interface.py:309, in AnnDataInterface.iloc(cls, dataset, index)
    306 dims = cls.dims(dataset)
    307 adata = cast("AnnData", dataset.data)
--> 309 if (idx := cls._iloc_2d(dims, rows, cols)) is not None:
    310     return adata[idx]
    312 match dims[0]:

File ~/checkouts/readthedocs.org/user_builds/hv-anndata/checkouts/latest/src/hv_anndata/interface.py:332, in AnnDataInterface._iloc_2d(cls, dims, rows, cols)
    326 if cols != slice(None):
    327     msg = (
    328         f"When indexing using .iloc on {dims[0]} indexed data, "
    329         "you may only select rows along that dimension, "
    330         "i.e. you may not provide a column selection."
    331     )
--> 332     raise IndexError(msg)
    333 return None

IndexError: When indexing using .iloc on var indexed data, you may only select rows along that dimension, i.e. you may not provide a column selection.
:AdjointLayout
   :HeatMap   [A.obs.index,A.var.index]   (A.layers['mean'][:, :])
   :Bars   [A.var.index]   (totals)