Skip to content

Commit e0238c3

Browse files
committed
fix(utils): keep set_zero_in_cmap_to_transparent public
The utils split (#696) relocated the public set_zero_in_cmap_to_transparent into the private _color module, breaking the only public import path: `from spatialdata_plot.pl.utils import set_zero_in_cmap_to_transparent`. Move it back to utils.py — a public symbol belongs in a public module, and a re-export shim would re-introduce the _color<->utils cycle the split removed (utils is the import-graph leaf). Point the test at the public path.
1 parent a7881d1 commit e0238c3

3 files changed

Lines changed: 25 additions & 27 deletions

File tree

‎src/spatialdata_plot/pl/_color.py‎

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from typing import Any, Literal
88

99
import matplotlib
10-
import matplotlib.pyplot as plt
1110
import numpy as np
1211
import pandas as pd
1312
import spatialdata as sd
@@ -1211,25 +1210,3 @@ def _maybe_set_colors(
12111210

12121211
def _get_linear_colormap(colors: list[str], background: str) -> list[LinearSegmentedColormap]:
12131212
return [LinearSegmentedColormap.from_list(c, [background, c], N=256) for c in colors]
1214-
1215-
1216-
def set_zero_in_cmap_to_transparent(cmap: Colormap | str, steps: int | None = None) -> ListedColormap:
1217-
"""
1218-
Modify colormap so that 0s are transparent.
1219-
1220-
Parameters
1221-
----------
1222-
cmap (Colormap | str): A matplotlib Colormap instance or a colormap name string.
1223-
steps (int): The number of steps in the colormap.
1224-
1225-
Returns
1226-
-------
1227-
ListedColormap: A new colormap instance with modified alpha values.
1228-
"""
1229-
if isinstance(cmap, str):
1230-
cmap = plt.get_cmap(cmap)
1231-
1232-
colors = cmap(np.arange(steps or cmap.N))
1233-
colors[0, :] = [1.0, 1.0, 1.0, 0.0]
1234-
1235-
return ListedColormap(colors)

‎src/spatialdata_plot/pl/utils.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from matplotlib.axes import Axes
2222
from matplotlib.collections import PatchCollection
2323
from matplotlib.colors import (
24+
Colormap,
2425
ListedColormap,
2526
)
2627
from matplotlib.figure import Figure
@@ -1209,6 +1210,28 @@ def _resolve_measure_table(sdata: SpatialData, element_name: str, table_name: st
12091210
return str(annotators[0])
12101211

12111212

1213+
def set_zero_in_cmap_to_transparent(cmap: Colormap | str, steps: int | None = None) -> ListedColormap:
1214+
"""
1215+
Modify colormap so that 0s are transparent.
1216+
1217+
Parameters
1218+
----------
1219+
cmap (Colormap | str): A matplotlib Colormap instance or a colormap name string.
1220+
steps (int): The number of steps in the colormap.
1221+
1222+
Returns
1223+
-------
1224+
ListedColormap: A new colormap instance with modified alpha values.
1225+
"""
1226+
if isinstance(cmap, str):
1227+
cmap = plt.get_cmap(cmap)
1228+
1229+
colors = cmap(np.arange(steps or cmap.N))
1230+
colors[0, :] = [1.0, 1.0, 1.0, 0.0]
1231+
1232+
return ListedColormap(colors)
1233+
1234+
12121235
def measure_obs(
12131236
sdata: SpatialData,
12141237
element: str | None = None,

‎tests/pl/test_utils.py‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
_datashader_map_aggregate_to_color,
1919
)
2020
from spatialdata_plot.pl.render_params import Color, ColorLike
21-
from spatialdata_plot.pl._color import (
22-
_set_outline,
23-
set_zero_in_cmap_to_transparent,
24-
)
21+
from spatialdata_plot.pl._color import _set_outline
22+
from spatialdata_plot.pl.utils import set_zero_in_cmap_to_transparent
2523
from tests.conftest import DPI, PlotTester, PlotTesterMeta
2624

2725
sc.pl.set_rcParams_defaults()

0 commit comments

Comments
 (0)