Skip to content

make outline behavior more similar to squidpy #472

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

Sonja-Stockhaus
Copy link
Collaborator

For outsourcing the plotting from squidpy to spatialdata-plot: refactor the outlines of the shapes to be more similar to squidpy. This includes:

  1. outlines always lie behind the shapes (both are rendered separately with the shapes on top of the outlines). Note: since the usual behavior of mpl and ds is to draw the line so that half of it lies "within" and the other half outside the shape, the outlines will shine through for instance if alpha_fill < 1.0!
  2. enabling a double outline. Now, the arguments outline_width and outline_color take either a single argument as before, or a tuple of two values referring to the outer and inner outline. If one of the two arguments indicates that 2 outlines should be drawn but the other is not used (or only contains of 1 value which would be interpreted as referring to the outer outline), the missing value(s) are set to the defaults which are for the outer outline: 1.5 and "black" and for the inner outline: 0.5 and "white". If the linewidth for the inner outline is wider than the one of the outer outline, it will hide the outer outline (if alpha = 1.0).

@codecov-commenter
Copy link

codecov-commenter commented Jun 17, 2025

Codecov Report

Attention: Patch coverage is 79.77528% with 18 lines in your changes missing coverage. Please review.

Project coverage is 85.02%. Comparing base (c5cb734) to head (87fb577).

Files with missing lines Patch % Lines
src/spatialdata_plot/pl/utils.py 71.92% 16 Missing ⚠️
src/spatialdata_plot/pl/render.py 93.10% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   85.00%   85.02%   +0.01%     
==========================================
  Files           8        8              
  Lines        1794     1856      +62     
==========================================
+ Hits         1525     1578      +53     
- Misses        269      278       +9     
Files with missing lines Coverage Δ
src/spatialdata_plot/pl/basic.py 89.26% <ø> (ø)
src/spatialdata_plot/pl/render_params.py 100.00% <100.00%> (ø)
src/spatialdata_plot/pl/render.py 96.65% <93.10%> (+0.17%) ⬆️
src/spatialdata_plot/pl/utils.py 78.13% <71.92%> (-0.07%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sonja-Stockhaus
Copy link
Collaborator Author

Note: when alpha_fill = 1.0, you only see half of the outline, since the "inner part" lies behind the actual shape. So the outline will appear narrower than you might expect from the outline_width parameter

@Sonja-Stockhaus
Copy link
Collaborator Author

Regarding the "outline lies partly behind shape and will shine through if fill_alpha != 1" issue:

  • a nicer solution might be to upscale the shapes that are used for plotting the outline(s) so that the outline perfectly lies around the shape
  • for circles, that's easy: in the _process_point() sub-method in utils._get_collection_shape(), one can compute added_size_for_outline = 0.5 * linewidth and add that value to the radius of the mpatches.Circle objects
  • however, for polygons it gets more complicated, since the points whould have to be shifted away from the centroid by a value that does not only depend on the linewidth but also the angle. I did not reach a satisfying solution there and it would get even more complex with concave shapes or multipolygons
  • there might be an easier solution using shapely, but so far we think it's too much effort/perfectionism for too little improvement. So for now, we stick to the default matplotlib/datashader behavior.

@Sonja-Stockhaus Sonja-Stockhaus marked this pull request as ready for review June 18, 2025 10:49
@Sonja-Stockhaus Sonja-Stockhaus requested a review from timtreis June 18, 2025 10:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants