Skip to content

Commit 08e5eb5

Browse files
authored
Plot Voronoi cells in correct order for neighborhood plot (#479)
Voronoi cells are now plotted in the following order: default, neighbors, base. That way we ensure that the result looks better than with "random" order.
1 parent aabeeb2 commit 08e5eb5

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

pedpy/plotting/plotting.py

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -833,15 +833,25 @@ def _plot_neighborhood(
833833
axes.set_xlim(x_min - margin_x, x_max + margin_x)
834834
axes.set_ylim(y_min - margin_y, y_max + margin_y)
835835

836-
# Plot each polygon with precomputed colors and alphas
837-
for poly, color, alpha in zip(polygons, colors, alphas, strict=False):
838-
_plot_polygon(
839-
axes=axes,
840-
polygon=poly,
841-
line_color=color,
842-
polygon_color=color,
843-
polygon_alpha=alpha,
844-
)
836+
# Create boolean masks for each type of polygon
837+
default_mask = np.all(colors == default_color, axis=1)
838+
neighbor_mask = np.all(colors == neighbor_color, axis=1)
839+
base_mask = np.all(colors == base_color, axis=1)
840+
841+
# Plot polygons in order: default -> neighbors -> base
842+
for mask, color, alpha in [
843+
(default_mask, default_color, default_alpha),
844+
(neighbor_mask, neighbor_color, neighbor_alpha),
845+
(base_mask, base_color, base_alpha),
846+
]:
847+
for poly in polygons[mask]:
848+
_plot_polygon(
849+
axes=axes,
850+
polygon=poly,
851+
line_color=color,
852+
polygon_color=color,
853+
polygon_alpha=alpha,
854+
)
845855

846856
# Set aspect ratio
847857
axes.set_aspect("equal")

0 commit comments

Comments
 (0)