Skip to content

Commit

Permalink
bugfix: None colormap
Browse files Browse the repository at this point in the history
  • Loading branch information
katosh committed Nov 19, 2024
1 parent 41d5fa8 commit d0adcf1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/palantir/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,10 +1155,13 @@ def plot_stats(
}
scatter_kwargs.update(kwargs)

try:
cmap = matplotlib.colormaps[cmap] if isinstance(cmap, str) else cmap
except KeyError:
if cmap is None:
cmap = matplotlib.colormaps["viridis"]
else:
try:
cmap = matplotlib.colormaps[cmap] if isinstance(cmap, str) else cmap
except KeyError:
cmap = matplotlib.colormaps["viridis"]
cmap = copy(cmap)
cmap.set_bad(na_color)

Expand Down
6 changes: 3 additions & 3 deletions src/palantir/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,10 +454,10 @@ def run_diffusion_maps(
and returned.
"""

if isinstance(data, pd.DataFrame):
data_df = data
else:
if isinstance(data, sc.AnnData):
data_df = pd.DataFrame(data.obsm[pca_key], index=data.obs_names)
else:
data_df = data

if not isinstance(data_df, pd.DataFrame) and not issparse(data_df):
raise ValueError("'data_df' should be a pd.DataFrame or sc.AnnData")
Expand Down
2 changes: 1 addition & 1 deletion tests/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def test_plot_stats_optional_parameters(mock_anndata):
def test_plot_stats_masking(mock_anndata):
# Create a condition here that you want to mask
mask_condition = mock_anndata.obs["palantir_pseudotime"] > 0.5
mock_anndata.obsm["branch_masks"] = mask_condition
mock_anndata.obsm["branch_masks"] = pd.DataFrame({"mock_branch": mask_condition})
fig, ax = plot_stats(
mock_anndata,
x="palantir_pseudotime",
Expand Down

0 comments on commit d0adcf1

Please sign in to comment.