Skip to content

BUG: Fix box_handle_props initialization in PolygonSelector#31718

Open
lucaznch wants to merge 1 commit into
matplotlib:mainfrom
lucaznch:fix/box-handle-props
Open

BUG: Fix box_handle_props initialization in PolygonSelector#31718
lucaznch wants to merge 1 commit into
matplotlib:mainfrom
lucaznch:fix/box-handle-props

Conversation

@lucaznch
Copy link
Copy Markdown
Contributor

PR summary

This PR fixes a bug in PolygonSelector where box_handle_props is incorrectly set to None because dict.update() returns None. Discovered while working on #31623.

Why is this change necessary? / What problem does it solve?

When using PolygonSelector with draw_bounding_box=True, any provided box_handle_props are not applied correctly. Instead the bounding box handles fall back to default props from RectangleSelector.

What is the reasoning for this implementation?

The fix ensures box_handle_props inherits from handle_props, overrides are applied correctly, and the original handle_props dictionary is not mutated.

Example

The issue can be reproduced by specifying box_handle_props:

import matplotlib.pyplot as plt
from matplotlib.widgets import PolygonSelector

fig, ax = plt.subplots()

box_handle_props = dict(marker='o', markerfacecolor='g', markeredgecolor='b')

selector = PolygonSelector(ax, draw_bounding_box=True,
                           box_handle_props=box_handle_props)

selector.verts = [(0.3, 0.3), (0.7, 0.4), (0.4, 0.8)]

plt.show()
box_handle_props_image_comparison

AI Disclosure

None.

PR checklist

Comment thread lib/matplotlib/tests/test_widgets.py Outdated
@lucaznch lucaznch force-pushed the fix/box-handle-props branch from 45071c9 to c66fb6a Compare May 21, 2026 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants