Skip to content

Allow different clipping on InsetIndicator rectangle and connectors.#30648

Draft
juseg wants to merge 13 commits into
matplotlib:mainfrom
juseg:inset-clipping
Draft

Allow different clipping on InsetIndicator rectangle and connectors.#30648
juseg wants to merge 13 commits into
matplotlib:mainfrom
juseg:inset-clipping

Conversation

@juseg

@juseg juseg commented Oct 10, 2025

Copy link
Copy Markdown

PR summary

This adds clip_on to the tuple of _shared_properties in matplotlib.inset so that InsetIndicator recognizes that its rectangle and connectors components should be drawn independently if they have different clip_on values (closes #30642, see that issue for a minimal example).

PR checklist

@dstansby

Copy link
Copy Markdown
Member

Thanks for the PR - are you still interested on working on this? Before it's ready to be reviewed, it still needs a test adding to make sure we don't accidentally introduce the bug again later down the line.

@juseg

juseg commented Jan 13, 2026

Copy link
Copy Markdown
Author

Thank you for the comment! I am interested to put more work in, but not yet sure how to go about tests. The bug is caused by code in the indicator's draw() method, specifically these lines:

for s in _shared_properties:
if artist.getp(self._rectangle, s) != artist.getp(conn, s):
# Draw this connector by itself
conn.draw(renderer)
drawn = True
break

Because of that the result of get_clip_on() is irrelevant to the final output. Do you think an image comparison test (doc below) is the way to go or is there a better way to test what is happening in draw()?

https://matplotlib.org/devdocs/devel/testing.html#compare-two-methods-of-creating-an-image

@dstansby

Copy link
Copy Markdown
Member

The easiest way to add a test would be to modify this existing test:

@image_comparison(['zoom_inset_connector_styles.png'], remove_text=True, style='mpl20',
tol=0.024 if platform.machine() == 'arm64' else 0)
def test_zoom_inset_connector_styles():
fig, axs = plt.subplots(2)
for ax in axs:
ax.plot([1, 2, 3])
axs[1].set_xlim(0.5, 1.5)
indicator = axs[0].indicate_inset_zoom(axs[1], linewidth=5)
# Make one visible connector a different style
indicator.connectors[1].set_linestyle('dashed')
indicator.connectors[1].set_color('blue')

by setting the clip_on value of one of the connectors at the end. If all works well, the new test image show show that one of the connectors is clipped.

@rcomer

rcomer commented Jun 22, 2026

Copy link
Copy Markdown
Member

Hi @juseg are you still interested in working on this? Do you need any more help?

@juseg

juseg commented Jul 9, 2026

Copy link
Copy Markdown
Author

Hi @rcomer thanks for the heads-up and sorry for letting this sleep, I am back at it will try and add tests based on the advice above!

@github-actions github-actions Bot added the Documentation: examples files in galleries/examples label Jul 10, 2026
@juseg

juseg commented Jul 10, 2026

Copy link
Copy Markdown
Author
  • I reworked the image comparison test as suggested.
  • Amended another test on rectangle and connector properties.
  • I added an example using clip_on=True on the rectangle but not the connectors to draw an inset indicator over broken axes (this is actually my original use case for wanting this implemented).

I am happy to get feedback at this stage. Specifically:

  • Is this considered "new features and API changes" (see PR checklist)?
  • Do we want clip_on=True by default on the rectangle, while keeping it False on the connectors (it would seem like a logical choice to me, but also a breaking change)?

Edit: @melissawm Github Actions seems to remove that topic: axes tag with every commit.

@melissawm

Copy link
Copy Markdown
Member

Huh! Looks like a bug in our labeler action - I'll take a look. Thanks for flagging @juseg !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: InsetIndicator rectangle and connectors forced to share clip_on property

5 participants