Skip to content

Pl.hist fails if no ax is passed #57

@lucas-diedrich

Description

@lucas-diedrich

As ax is per default None it should not be necessary to pass an axes object.

Report

Code to reproduce

from alphatools.pl.figure import create_figure
from alphatools.pl.plots import Plots

fig, axm = create_figure(figsize=(5, 3))
ax = axm.next()
Plots.histogram(adata, value_column="missingness")

Error:

INFO:root:Column 'missingness' found in: data.obs.columns. Using that
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[28], [line 11](vscode-notebook-cell:?execution_count=28&line=11)
      9 fig, axm = create_figure(figsize=(5, 3))
     10 ax = axm.next()
---> [11](vscode-notebook-cell:?execution_count=28&line=11) Plots.histogram(adata, value_column="missingness")

File ~/mamba/envs/scproteomics/lib/python3.12/site-packages/alphatools/pl/plots.py:674, in Plots.histogram(cls, data, value_column, color_map_column, bins, ax, color, palette, color_dict, legend, hist_kwargs, legend_kwargs, xlim, ylim)
    672 if color_map_column is None:
    673     color = BaseColors.get(color)
--> [674](https://file+.vscode-resource.vscode-cdn.net/Users/lucas-diedrich/Documents/Projects/scproteomics/multimodal/analysis/notebooks/proteomics/~/mamba/envs/scproteomics/lib/python3.12/site-packages/alphatools/pl/plots.py:674)     ax.hist(values, bins=bins, color=color, **hist_kwargs)
    675 else:
    676     color_levels = _array_to_str(
    677         _adata_column_to_array(data, color_map_column)
    678     )  # Safe types: convert the color_map_column values to strings

AttributeError: 'AxisManager' object has no attribute 'hist'

Successful

from alphatools.pl.figure import create_figure
from alphatools.pl.plots import Plots

fig, axm = create_figure(figsize=(5, 3))
ax = axm.next()
Plots.histogram(adata, value_column="missingness", ax=ax)

Version information

alphatools @ git+https://github.com/MannLabs/alphatools.git@336917ed17e3e6329a327f56006c08950cfb27cc

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions