hv_anndata.plotting.scanpy.scatter¶
- hv_anndata.plotting.scanpy.scatter(adata, /, kdims, vdims=(), *, color=None)¶
Shortcut for a scatter plot.
Basically just
>>> hv.Scatter(adata, kdims[0], [kdims[1], *vdims]).opts(aspect="square", ...)
If
coloris set, it’s both added tovdimsand in.opts(color=...).- Parameters:
- adata
AnnData The AnnData object.
- kdims
Collection[AdDim] A sequence containing the x and y dimension.
- vdims
Collection[AdDim], default:() The value dimensions (
colorwill be added automatically).- color
AdDim|None, default:None The color dimension.
- adata
- Return type:
- Returns:
A scatter plot object
Examples
import hv_anndata.plotting.scanpy as hv_sc from hv_anndata import data, register, A register() adata = data.pbmc68k_processed() hv_sc.scatter(adata, A.X[:, ["PSAP", "C1QA"]], color=A.obs["bulk_labels"]).opts( cmap="tab10", show_legend=False )
import hv_anndata.plotting.scanpy as hv_sc from hv_anndata import data, register, A register() adata = data.pbmc68k_processed() hv_sc.scatter(adata, A.X[:, ["PSAP", "C1QA"]], color=A.obs["bulk_labels"]).opts( cmap="tab10", show_legend=False )
import hv_anndata.plotting.scanpy as hv_sc from hv_anndata import data, register, A register() adata = data.pbmc68k_processed() hv_sc.scatter(adata, A.X[:, ["PSAP", "C1QA"]], color=A.obs["bulk_labels"]).opts( cmap="tab10", show_legend=False )
WARNING:param.main: Option 'legend_position' for Scatter type not valid for selected backend ('plotly'). Option only applies to following backends: ['bokeh', 'matplotlib']--------------------------------------------------------------------------- ValueError 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:308, in display(obj, raw_output, **kwargs) 306 elif isinstance(obj, (CompositeOverlay, ViewableElement)): 307 with option_state(obj): --> 308 output = element_display(obj) 309 elif isinstance(obj, (Layout, NdLayout, AdjointLayout)): 310 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:246, in element_display(element, max_frames) 243 if type(element) not in Store.registry[backend]: 244 return None --> 246 return render(element) 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:498, in HoloViews._get_model(self, doc, root, parent, comm) 496 plot.pane = self 497 backend = plot.renderer.backend --> 498 state = plot.renderer.get_plot_state(plot) 500 # Ensure rerender if content is responsive but layout is centered 501 # or update layout if plot is height responsive but layout wrapper 502 # is not 503 self._sync_sizing_mode(plot) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/holoviews/plotting/plotly/renderer.py:86, in PlotlyRenderer.get_plot_state(self_or_cls, obj, doc, renderer, numpy_convert, **kwargs) 82 clean_internal_figure_properties(fig_dict) 84 # Run through Figure constructor to normalize keys 85 # (e.g. to expand magic underscore notation) ---> 86 fig_dict = go.Figure(fig_dict).to_dict() 87 fig_dict['config'] = config 89 # Remove template File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/graph_objs/_figure.py:72, in Figure.__init__(self, data, layout, frames, skip_invalid, **kwargs) 68 ValueError 69 if a property in the specification of data, layout, or frames 70 is invalid AND skip_invalid is False 71 """ ---> 72 super().__init__(data, layout, frames, skip_invalid, **kwargs) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:532, in BaseFigure.__init__(self, data, layout_plotly, frames, skip_invalid, **kwargs) 529 self._data_validator.set_uid = self._set_trace_uid 531 # ### Import traces ### --> 532 data = self._data_validator.validate_coerce( 533 data, skip_invalid=skip_invalid, _validate=self._validate 534 ) 536 # ### Save tuple of trace objects ### 537 self._data_objs = data File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/_plotly_utils/basevalidators.py:2669, in BaseDataValidator.validate_coerce(self, v, skip_invalid, _validate) 2667 invalid_els.append(v_el) 2668 else: -> 2669 trace = self.get_trace_class(trace_type)( 2670 skip_invalid=skip_invalid, _validate=_validate, **v_el 2671 ) 2672 res.append(trace) 2674 if type_in_v_el: 2675 # Restore type in v_el File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/graph_objs/_scatter.py:2797, in Scatter.__init__(self, arg, alignmentgroup, cliponaxis, connectgaps, customdata, customdatasrc, dx, dy, error_x, error_y, fill, fillcolor, fillgradient, fillpattern, groupnorm, hoverinfo, hoverinfosrc, hoverlabel, hoveron, hovertemplate, hovertemplatefallback, hovertemplatesrc, hovertext, hovertextsrc, ids, idssrc, legend, legendgroup, legendgrouptitle, legendrank, legendwidth, line, marker, meta, metasrc, mode, name, offsetgroup, opacity, orientation, selected, selectedpoints, showlegend, stackgaps, stackgroup, stream, text, textfont, textposition, textpositionsrc, textsrc, texttemplate, texttemplatefallback, texttemplatesrc, uid, uirevision, unselected, visible, x, x0, xaxis, xcalendar, xhoverformat, xperiod, xperiod0, xperiodalignment, xsrc, y, y0, yaxis, ycalendar, yhoverformat, yperiod, yperiod0, yperiodalignment, ysrc, zorder, **kwargs) 2795 self._set_property("legendwidth", arg, legendwidth) 2796 self._set_property("line", arg, line) -> 2797 self._set_property("marker", arg, marker) 2798 self._set_property("meta", arg, meta) 2799 self._set_property("metasrc", arg, metasrc) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:4403, in BasePlotlyType._set_property(self, name, arg, provided) 4397 def _set_property(self, name, arg, provided): 4398 """ 4399 Initialize a property of this object using the provided value 4400 or a value popped from the arguments dictionary. If neither 4401 is available, do not set the property. 4402 """ -> 4403 _set_property_provided_value(self, name, arg, provided) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:398, in _set_property_provided_value(obj, name, arg, provided) 396 val = provided if provided is not None else val 397 if val is not None: --> 398 obj[name] = val File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:4924, in BasePlotlyType.__setitem__(self, prop, value) 4922 # ### Handle compound property ### 4923 if isinstance(validator, CompoundValidator): -> 4924 self._set_compound_prop(prop, value) 4926 # ### Handle compound array property ### 4927 elif isinstance(validator, (CompoundArrayValidator, BaseDataValidator)): File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:5335, in BasePlotlyType._set_compound_prop(self, prop, val) 5332 # Import value 5333 # ------------ 5334 validator = self._get_validator(prop) -> 5335 val = validator.validate_coerce(val, skip_invalid=self._skip_invalid) 5337 # Save deep copies of current and new states 5338 # ------------------------------------------ 5339 curr_val = self._compound_props.get(prop, None) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/_plotly_utils/basevalidators.py:2468, in CompoundValidator.validate_coerce(self, v, skip_invalid, _validate) 2465 v = self.data_class() 2467 elif isinstance(v, dict): -> 2468 v = self.data_class(v, skip_invalid=skip_invalid, _validate=_validate) 2470 elif isinstance(v, self.data_class): 2471 # Copy object 2472 v = self.data_class(v) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/graph_objs/scatter/_marker.py:1108, in Marker.__init__(self, arg, angle, angleref, anglesrc, autocolorscale, cauto, cmax, cmid, cmin, color, coloraxis, colorbar, colorscale, colorsrc, gradient, line, maxdisplayed, opacity, opacitysrc, reversescale, showscale, size, sizemin, sizemode, sizeref, sizesrc, standoff, standoffsrc, symbol, symbolsrc, **kwargs) 1106 self._set_property("cmid", arg, cmid) 1107 self._set_property("cmin", arg, cmin) -> 1108 self._set_property("color", arg, color) 1109 self._set_property("coloraxis", arg, coloraxis) 1110 self._set_property("colorbar", arg, colorbar) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:4403, in BasePlotlyType._set_property(self, name, arg, provided) 4397 def _set_property(self, name, arg, provided): 4398 """ 4399 Initialize a property of this object using the provided value 4400 or a value popped from the arguments dictionary. If neither 4401 is available, do not set the property. 4402 """ -> 4403 _set_property_provided_value(self, name, arg, provided) File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:398, in _set_property_provided_value(obj, name, arg, provided) 396 val = provided if provided is not None else val 397 if val is not None: --> 398 obj[name] = val File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:4932, in BasePlotlyType.__setitem__(self, prop, value) 4928 self._set_array_prop(prop, value) 4930 # ### Handle simple property ### 4931 else: -> 4932 self._set_prop(prop, value) 4933 else: 4934 # Make sure properties dict is initialized 4935 self._init_props() File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:5276, in BasePlotlyType._set_prop(self, prop, val) 5274 return 5275 else: -> 5276 raise err 5278 # val is None 5279 # ----------- 5280 if val is None: 5281 # Check if we should send null update File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/plotly/basedatatypes.py:5271, in BasePlotlyType._set_prop(self, prop, val) 5268 validator = self._get_validator(prop) 5270 try: -> 5271 val = validator.validate_coerce(val) 5272 except ValueError as err: 5273 if self._skip_invalid: File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/_plotly_utils/basevalidators.py:1379, in ColorValidator.validate_coerce(self, v, should_raise) 1376 invalid_els = self.find_invalid_els(v, validated_v) 1378 if invalid_els and should_raise: -> 1379 self.raise_invalid_elements(invalid_els) 1381 # ### Check that elements have valid colors types ### 1382 elif self.numbers_allowed() or invalid_els: File ~/.local/share/hatch/env/virtual/hv-anndata/STk7F69l/docs/lib/python3.13/site-packages/_plotly_utils/basevalidators.py:328, in BaseValidator.raise_invalid_elements(self, invalid_els) 326 def raise_invalid_elements(self, invalid_els): 327 if invalid_els: --> 328 raise ValueError( 329 """ 330 Invalid element(s) received for the '{name}' property of {pname} 331 Invalid elements include: {invalid} 332 333 {valid_clr_desc}""".format( 334 name=self.plotly_name, 335 pname=self.parent_name, 336 invalid=invalid_els[:10], 337 valid_clr_desc=self.description(), 338 ) 339 ) ValueError: Invalid element(s) received for the 'color' property of scatter.marker Invalid elements include: ['CD14+ Monocyte', 'Dendritic', 'CD56+ NK', 'CD4+/CD25 T Reg', 'Dendritic', 'CD19+ B', 'Dendritic', 'Dendritic', 'CD8+ Cytotoxic T', 'CD14+ Monocyte'] The 'color' property is a color and may be specified as: - A hex string (e.g. '#ff0000') - An rgb/rgba string (e.g. 'rgb(255,0,0)') - An hsl/hsla string (e.g. 'hsl(0,100%,50%)') - An hsv/hsva string (e.g. 'hsv(0,100%,100%)') - A named CSS color: see https://plotly.com/python/css-colors/ for a list - A number that will be interpreted as a color according to scatter.marker.colorscale - A list or array of any of the above
:Scatter [A.X[:, 'PSAP']] (C1QA,bulk_labels)