Skip to content

BUG: Fix box_handle_props initialization in PolygonSelector#31718

Merged
ksunden merged 1 commit into
matplotlib:mainfrom
lucaznch:fix/box-handle-props
May 29, 2026
Merged

BUG: Fix box_handle_props initialization in PolygonSelector#31718
ksunden merged 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
@QuLogic QuLogic added this to the v3.11.0 milestone May 23, 2026
@lucaznch lucaznch force-pushed the fix/box-handle-props branch from c66fb6a to 1e50bb2 Compare May 24, 2026 18:28
Comment thread lib/matplotlib/tests/test_widgets.py Outdated
Comment on lines +1748 to +1749
assert box_artist.get_facecolor() == mcolors.to_rgba('c')
assert box_artist.get_edgecolor() == mcolors.to_rgba('b')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert box_artist.get_facecolor() == mcolors.to_rgba('c')
assert box_artist.get_edgecolor() == mcolors.to_rgba('b')
assert mcolors.same_color(box_artist.get_facecolor(), 'c')
assert mcolors.same_color(box_artist.get_edgecolor(), 'b')

Two more color checks

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I overlooked those. Updated now.

@lucaznch lucaznch force-pushed the fix/box-handle-props branch from 1e50bb2 to 8a06e06 Compare May 29, 2026 19:15
@ksunden ksunden merged commit aa76457 into matplotlib:main May 29, 2026
33 of 35 checks passed
QuLogic pushed a commit that referenced this pull request May 30, 2026
QuLogic added a commit that referenced this pull request May 30, 2026
…718-on-v3.11.x

Backport PR #31718 on branch v3.11.x (BUG: Fix box_handle_props initialization in PolygonSelector)
@lucaznch lucaznch deleted the fix/box-handle-props branch May 30, 2026 18:44
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.

3 participants