Skip to content

feat: add text_style to plot_labelbox, and make the label background follow the box edge color - #273

Merged
petercorke merged 2 commits into
mainfrom
feat/labelbox-text-style
Nov 23, 2026
Merged

petercorke merged 2 commits into
mainfrom
feat/labelbox-text-style

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Adds a text_style argument to plot_labelbox and Blobs.plot_labelbox, and fixes the label background not following the edge color of the box. It follows the <thing>_style convention in rvc-ecosystem Issue 15 (open) and is item 36 of the same style work as PR 269 (merged).

text_style. The label could only be given a color, and its font was not settable at all, though the docstring said the label font is "specified using the same arguments as for plot_text". text_style is a dict of Matplotlib text options (dict(fontsize=12, fontweight="bold")). Short names are accepted (size, c, weight), as the label is merged through mpl_styling(..., artist=Text) from PR 266. A bbox dict in it is merged over the default borderless background, so a border or rounded corners can be added.

The box stays on fmt and **kwargs as before, so existing calls are unchanged. Blobs.plot_labelbox now has position, textcolor, labelcolor and text_style as explicit keyword-only arguments; position, textcolor and labelcolor already worked, by passing through **kwargs.

Three sources for the text color and the background. The most specific one wins:

text color label background
1. text_style color backgroundcolor, or the facecolor of bbox
2. the shorthand textcolor labelcolor
3. the default black the final edge color of the box

The shorthands stay because draw_labelbox (the OpenCV twin) has them, and they are the simple form to read in the book. This is documented in both docstrings.

Bug fixed. The default background used to be the color option of the box only. With edgecolor="red" or ec="red" the box turned red and the label stayed yellow. It is now the final edge color of the box, however it was set (color, edgecolor, ec or the format string).

position now raises ValueError for an unknown value; before, it failed with UnboundLocalError. .. versionchanged:: 2.5.0 is added to both docstrings.

Tests: 11 new in tests/test_image_blobs.py: the default, the background following color, edgecolor, ec and the format string, the shorthands, text_style, short names, precedence, a merged bbox, position, the bad position, and that the caller's dict is not changed. 6 tests and 2 subtests fail on the old code. mypy reports no issues and the full suite passes (2289 passed, 30 skipped).

AI-assisted: written with Claude Code (Claude Sonnet 5.5) and reviewed by the maintainer.

🤖 Generated with Claude Code

petercorke and others added 2 commits November 24, 2026 08:37
…follow the box edge color

The label text could only be given a color, and the label background took the
color option of the box, so edgecolor= or ec= left it yellow. Add text_style
(Matplotlib text options, merged with short names converted), make position,
textcolor and labelcolor explicit arguments of Blobs.plot_labelbox, and take the
default background from the final edge color of the box.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 16 complexity · 0 duplication

Metric Results
Complexity 16
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@petercorke
petercorke merged commit dd6decc into main Nov 23, 2026
34 checks passed
@petercorke
petercorke deleted the feat/labelbox-text-style branch November 23, 2026 22:55
@github-actions github-actions Bot mentioned this pull request Nov 23, 2026
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.

1 participant