Skip to content

Implement interactive_errorbar() (and other fixes)#298

Open
JamesWrigley wants to merge 4 commits intompl-extensions:mainfrom
JamesWrigley:callable
Open

Implement interactive_errorbar() (and other fixes)#298
JamesWrigley wants to merge 4 commits intompl-extensions:mainfrom
JamesWrigley:callable

Conversation

@JamesWrigley
Copy link
Copy Markdown
Contributor

The bulk of the code implements interactive_errorbar(), which allows passing x/y/xerr/yerr as functions. There are two other unrelated changes I made while writing this:

Replaces #297.

Disclaimer: almost all of the changes were generated by Claude 🤖 Though I did go through it myself and make some tweaks.

@JamesWrigley
Copy link
Copy Markdown
Contributor Author

Ok, CI passes now 🟢

@JamesWrigley
Copy link
Copy Markdown
Contributor Author

(bump)

@ianhi
Copy link
Copy Markdown
Collaborator

ianhi commented Feb 17, 2026

sorry @JamesWrigley ! thank you for the bump. I will take a look today

@ianhi
Copy link
Copy Markdown
Collaborator

ianhi commented Feb 18, 2026

that was untrue I got caught up in things :( but today for sure

@JamesWrigley
Copy link
Copy Markdown
Contributor Author

No worries :)

@ianhi
Copy link
Copy Markdown
Collaborator

ianhi commented Feb 18, 2026

if only i hadn't gotten a real job

Copy link
Copy Markdown
Collaborator

@ianhi ianhi left a comment

Choose a reason for hiding this comment

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

Really nice work @JamesWrigley

I have two blocking requests, each of which have some detail in the review on the lines.

  1. Can't remove image segmenter without importing the replacement and throwing up a strong warning
  2. simplify the callable check.

and a few other suggestions/thoughts that aren't hard requiremnts (see review).

Really glad to see errorbar here. it was a missing piece that definitely limited functionality. Curious what, if any, your motivating use case was?

Comment on lines +115 to +118
if not isinstance(arg, Callable):
return False
else:
return not hasattr(arg, "__array__")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I appreciate the docstring otherwise id be confused to find this down the line :)

Let's simplify this a bit into a one-liner (fine to keep as a function)

Suggested change
if not isinstance(arg, Callable):
return False
else:
return not hasattr(arg, "__array__")
return isinstance(arg, Callable) and not hasattr(arg, "__array__")

Comment on lines +405 to +406
container.remove()
container = ax.errorbar(x_, y_, yerr=yerr_, xerr=xerr_, fmt=fmt, **eb_kwargs)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This works. and I do think that that it a nice and important addition to the library. But I'd definitely prefer if we modified the data properties of the existing errorbar components instead of creating a new errorbar. This is more complex than this be has the benefits of improved performance (not constantly creating and throwing away complex artist objects) and crucially maintaining drawing order properly in complex plots.

We can use https://matplotlib.org/stable/api/container_api.html#matplotlib.container.ErrorbarContainer which is returned from the initial errorbar call

though that said the logic here is kinda a lot :( https://github.com/matplotlib/matplotlib/blob/v3.10.8/lib/matplotlib/axes/_axes.py#L3515-L3894

I wish that the logic of processing and then display logic was decoupled in mpl. that would make this so much easier.

So in conclusion would appreciate it if you took a crack at the more complex full update approach, but please don't sink too much time into it, this current state is still a definite improvement - but the limitations should be noted in the docstring.

Comment on lines +431 to +439

if not isinstance(xlim, str):
ax.set_xlim(xlim)
if not isinstance(ylim, str):
ax.set_ylim(ylim)

if hasattr(fig.canvas, "toolbar") and fig.canvas.toolbar is not None:
fig.canvas.toolbar.push_current()
sca(ax)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is just a personal musing, not a request. Its a real mess that I have library with so much repeated code :( I should really have fixed that.

Comment on lines -419 to -421
class image_segmenter:
"""Manually segment an image with the lasso selector."""

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We can't just remove this like this unfortunately. There are people out there who use this and I don't want to just break them. Instead please:

import from mpl-image-segmenter and make that avialable here with a compatibility layer accounting for the differences: https://mpl-image-segmenter.readthedocs.io/en/latest/differences.html

and raise a warning (unfortunately deprecation warnings get swallowed - so maybe a print statement, or a custom warning) that this going to go away and provide a link to the new package.

OR

don't delete, just delete whatever image_segmenter test was failing - and I will do the above in a follow up PR.

Comment on lines +77 to +92
"def x_func(tau):\n",
" return np.linspace(0, 2 * np.pi * tau, 50)\n",
"\n",
"\n",
"def y_func(x, tau):\n",
" return np.sin(x)\n",
"\n",
"\n",
"def yerr_func(tau):\n",
" return np.full(50, 0.1 * tau)\n",
"\n",
"\n",
"def xerr_func(tau):\n",
" return np.full(50, 0.05 * tau)\n",
"\n",
"\n",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this might be a better example if they weren't all linked via tau. feels little overloaded. Even if in real life use cases the period and the error are linked having a separate control for xerr and yerr and the values feels like it demonstrates the range of possiblities a bit

@ianhi
Copy link
Copy Markdown
Collaborator

ianhi commented Feb 19, 2026

Also I was jsut looking at your profile and wanted to know more about what is going on at your xfel (I've been to the stanford one to do a beamtime once!) and noticed that your website link seems broken: https://jamesw.bio/ so heads up there

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.

2 participants