Skip to content

Commit 8fce7dd

Browse files
author
Sonja Stockhaus
committed
changelog and cleanup
1 parent b244402 commit 8fce7dd

File tree

2 files changed

+2
-19
lines changed

2 files changed

+2
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning][].
2121
### Fixed
2222

2323
- Fix color assignment for NaN values (#257)
24+
- Zorder of rendering now strictly follows the order of the render_x calls (#244)
2425

2526
## [0.2.2] - 2024-05-02
2627

src/spatialdata_plot/pl/render.py

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def _render_shapes(
149149
# Apply the transformation to the PatchCollection's paths
150150
trans = get_transformation(sdata_filt.shapes[element], get_all=True)[coordinate_system]
151151
affine_trans = trans.to_affine_matrix(input_axes=("x", "y"), output_axes=("x", "y"))
152-
trans = mtransforms.Affine2D(matrix=affine_trans)
152+
trans = mtransforms.Affine2D(matrix=affine_trans) + ax.transData
153153

154154
shapes = gpd.GeoDataFrame(shapes, geometry="geometry")
155155

@@ -162,9 +162,6 @@ def _render_shapes(
162162
logger.info(f"Using {method}")
163163

164164
if method == "datashader":
165-
# TODO: Where to put this
166-
trans = mtransforms.Affine2D(matrix=affine_trans) + ax.transData
167-
168165
extent = get_extent(sdata.shapes[element])
169166
x_ext = extent["x"][1]
170167
y_ext = extent["y"][1]
@@ -186,7 +183,6 @@ def _render_shapes(
186183

187184
# in case we are coloring by a column in table
188185
if col_for_color is not None and col_for_color not in sdata_filt.shapes[element].columns:
189-
# numerical
190186
sdata_filt.shapes[element][col_for_color] = (
191187
color_vector if color_source_vector is None else color_source_vector
192188
)
@@ -199,7 +195,6 @@ def _render_shapes(
199195
sdata_filt.shapes[element], geometry="geometry", agg=ds.by(col_for_color, ds.count())
200196
)
201197
else:
202-
# numerical
203198
agg = cvs.polygons(sdata_filt.shapes[element], geometry="geometry", agg=ds.sum(column=col_for_color))
204199
# save min and max values for drawing the colorbar
205200
aggregate_with_sum = (agg.min(), agg.max())
@@ -226,7 +221,6 @@ def _render_shapes(
226221
cmap=render_params.cmap_params.cmap,
227222
)
228223
)
229-
# Render image
230224
rgba_image = np.transpose(ds_result.to_numpy().base, (0, 1, 2))
231225
_cax = ax.imshow(rgba_image, cmap=palette, zorder=render_params.zorder)
232226
_cax.set_transform(trans)
@@ -335,7 +329,6 @@ def _render_points(
335329

336330
if groups is not None and col_for_color is not None:
337331
points = points[points[col_for_color].isin(groups)]
338-
# in case no rows are left:
339332
if len(points) <= 0:
340333
raise ValueError(f"None of the groups {groups} could be found in the column '{col_for_color}'.")
341334

@@ -398,14 +391,6 @@ def _render_points(
398391
affine_trans = trans.to_affine_matrix(input_axes=("x", "y"), output_axes=("x", "y"))
399392
trans = mtransforms.Affine2D(matrix=affine_trans) + ax.transData
400393

401-
# color_source_vector is None when the values aren't categorical
402-
if color_source_vector is None and render_params.transfunc is not None:
403-
color_vector = render_params.transfunc(color_vector)
404-
405-
trans = get_transformation(sdata.points[element], get_all=True)[coordinate_system]
406-
affine_trans = trans.to_affine_matrix(input_axes=("x", "y"), output_axes=("x", "y"))
407-
trans = mtransforms.Affine2D(matrix=affine_trans) + ax.transData
408-
409394
norm = copy(render_params.cmap_params.norm)
410395

411396
method = render_params.method
@@ -435,7 +420,6 @@ def _render_points(
435420
plot_height = int(np.round(y_ext[1] - y_ext[0]))
436421

437422
# use datashader for the visualization of points
438-
# TODO: what about trans/norm at this point?
439423
cvs = ds.Canvas(plot_width=plot_width, plot_height=plot_height, x_range=x_ext, y_range=y_ext)
440424

441425
color_by_categorical = col_for_color is not None and points[col_for_color].values.dtype == object
@@ -444,7 +428,6 @@ def _render_points(
444428
if color_by_categorical:
445429
agg = cvs.points(sdata_filt.points[element], "x", "y", agg=ds.by(col_for_color, ds.count()))
446430
else:
447-
# numerical
448431
agg = cvs.points(sdata_filt.points[element], "x", "y", agg=ds.sum(column=col_for_color))
449432
# save min and max values for drawing the colorbar
450433
aggregate_with_sum = (agg.min(), agg.max())
@@ -633,7 +616,6 @@ def _render_images(
633616
clip=True,
634617
)
635618

636-
# TODO: can't be list anymore???
637619
if not isinstance(render_params.cmap_params, list):
638620
if render_params.cmap_params.norm is not None:
639621
layers[c] = render_params.cmap_params.norm(layers[c])

0 commit comments

Comments
 (0)