Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ tests/figures/
# other
_version.py
/temp/

# pixi
pixi.lock
30 changes: 6 additions & 24 deletions src/spatialdata_plot/pl/basic.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import sys
import warnings
from collections import OrderedDict
from copy import deepcopy
from pathlib import Path
Expand All @@ -23,6 +22,7 @@
from xarray import DataArray, DataTree

from spatialdata_plot._accessor import register_spatial_data_accessor
from spatialdata_plot._logging import logger
from spatialdata_plot.pl.render import (
_render_images,
_render_labels,
Expand Down Expand Up @@ -272,11 +272,7 @@ def render_shapes(
"""
# TODO add Normalize object in tutorial notebook and point to that notebook here
if "vmin" in kwargs or "vmax" in kwargs:
warnings.warn(
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
DeprecationWarning,
stacklevel=2,
)
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
params_dict = _validate_shape_render_params(
self._sdata,
element=element,
Expand Down Expand Up @@ -423,11 +419,7 @@ def render_points(
"""
# TODO add Normalize object in tutorial notebook and point to that notebook here
if "vmin" in kwargs or "vmax" in kwargs:
warnings.warn(
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
DeprecationWarning,
stacklevel=2,
)
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
params_dict = _validate_points_render_params(
self._sdata,
element=element,
Expand Down Expand Up @@ -544,11 +536,7 @@ def render_images(
"""
# TODO add Normalize object in tutorial notebook and point to that notebook here
if "vmin" in kwargs or "vmax" in kwargs:
warnings.warn(
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
DeprecationWarning,
stacklevel=2,
)
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
params_dict = _validate_image_render_params(
self._sdata,
element=element,
Expand Down Expand Up @@ -679,11 +667,7 @@ def render_labels(
"""
# TODO add Normalize object in tutorial notebook and point to that notebook here
if "vmin" in kwargs or "vmax" in kwargs:
warnings.warn(
"`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.",
DeprecationWarning,
stacklevel=2,
)
logger.warning("`vmin` and `vmax` are deprecated. Pass matplotlib `Normalize` object to norm instead.")
params_dict = _validate_label_render_params(
self._sdata,
element=element,
Expand Down Expand Up @@ -918,9 +902,7 @@ def show(
# go through tree

for i, cs in enumerate(coordinate_systems):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
sdata = self._copy()
sdata = self._copy()
_, has_images, has_labels, has_points, has_shapes = (
cs_contents.query(f"cs == '{cs}'").iloc[0, :].values.tolist()
)
Expand Down
22 changes: 12 additions & 10 deletions src/spatialdata_plot/pl/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def _render_shapes(
color_vector = np.asarray(color_vector, dtype=float)
if np.isnan(color_vector).any():
nan_count = int(np.isnan(color_vector).sum())
logger.warning(
f"Found {nan_count} NaN values in color data. These observations will be colored with the 'na_color'."
)
msg = f"Found {nan_count} NaN values in color data. These observations will be colored with the 'na_color'."
warnings.warn(msg, UserWarning, stacklevel=2)
logger.warning(msg)

# Using dict.fromkeys here since set returns in arbitrary order
# remove the color of NaN values, else it might be assigned to a category
Expand Down Expand Up @@ -656,12 +656,14 @@ def _render_points(
cols = sc.get.obs_df(adata, [col_for_color])
# maybe set color based on type
if isinstance(cols[col_for_color].dtype, pd.CategoricalDtype):
_maybe_set_colors(
source=adata,
target=adata,
key=col_for_color,
palette=palette,
)
uns_color_key = f"{col_for_color}_colors"
if uns_color_key in adata.uns:
_maybe_set_colors(
source=adata,
target=adata,
key=col_for_color,
palette=palette,
)

# when user specified a single color, we emulate the form of `na_color` and use it
default_color = (
Expand Down Expand Up @@ -778,7 +780,7 @@ def _render_points(
agg = agg.where((agg <= norm.vmin) | (np.isnan(agg)), other=2)
agg = agg.where((agg != norm.vmin) | (np.isnan(agg)), other=0.5)

color_key = (
color_key: list[str] | None = (
list(color_vector.categories.values)
if (type(color_vector) is pd.core.arrays.categorical.Categorical)
and (len(color_vector.categories.values) > 1)
Expand Down
Loading