Skip to content

Commit ab296b1

Browse files
committed
Made color choice easier
1 parent f130032 commit ab296b1

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

src/spatialdata_plot/pl/utils.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,13 @@ def _set_outline(
500500
gap_size = (point + (point * gap_width) * 2) ** 2
501501
bg_size = (np.sqrt(gap_size) + (point * bg_width) * 2) ** 2
502502
# the default black and white colors can be changes using the contour_config parameter
503-
bg_color, gap_color = outline_color
503+
if isinstance(outline_color, str):
504+
bg_color, gap_color = outline_color, outline_color
505+
elif len(outline_color) == 4 and all(isinstance(c, float) for c in outline_color):
506+
hex_color = matplotlib.colors.to_hex(outline_color)
507+
bg_color, gap_color = hex_color, hex_color
508+
else:
509+
bg_color, gap_color = outline_color
504510

505511
if outline:
506512
kwargs.pop("edgecolor", None) # remove edge from kwargs if present
Loading
Loading

tests/pl/test_render_shapes.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ def test_plot_can_render_circles(self, sdata_blobs: SpatialData):
2323
sdata_blobs.pl.render_shapes(elements="blobs_circles").pl.show()
2424

2525
def test_plot_can_render_circles_with_outline(self, sdata_blobs: SpatialData):
26-
sdata_blobs.pl.render_shapes(element="blobs_circles", outline=True).pl.show()
26+
sdata_blobs.pl.render_shapes(elements="blobs_circles", outline=True).pl.show()
27+
28+
def test_plot_can_render_circles_with_colored_outline(self, sdata_blobs: SpatialData):
29+
sdata_blobs.pl.render_shapes(elements="blobs_circles", outline=True, outline_color="red").pl.show()
2730

2831
def test_plot_can_render_polygons(self, sdata_blobs: SpatialData):
2932
sdata_blobs.pl.render_shapes(elements="blobs_polygons").pl.show()

0 commit comments

Comments
 (0)