Skip to content

[Bug]: Interactively switching plot to logit scale with some values out of range crashes UI and erases plot #29040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tchristiansen-aquaveo opened this issue Oct 29, 2024 · 1 comment

Comments

@tchristiansen-aquaveo
Copy link

tchristiansen-aquaveo commented Oct 29, 2024

Bug summary

The dialog shown via matplotlib.pyplot.show() has an "Edit axis, curve and image parameters" tool button that allows setting the axis. Setting it to the logit scale when your data is on the edge of the [0, 1] range results in a crash and the plot disappearing.

Code for reproduction

import matplotlib.pyplot as plt

fig, ax = plt.subplots(figsize=(6, 6))
ax.plot([1, 2], [1, 2], label="Line")

plt.show()

# In the dialog that appears:
# 1. Click the "Edit axis, curve and image parameters" tool button
# 2. Change either Scale dropdown to `logit`
# 3. Click Apply
# 4. Click OK
# 5. Click Cancel
# 6. Click the "Edit axis, curve and image parameters" tool button again
# 7. Change all the Scale dropdowns to `linear`
# 8. Click OK again

Actual outcome

  • Steps 3 and 4 produce no visible response from the UI. Both of them write stack traces to stdout (OverflowError), which are informative to developers, but unhelpful for non-programming users who just want to look at plots.
  • Step 5 closes the dialog as expected, but then the plot disappears entirely.
  • Step 8 makes the border of the plot reappear, but the line is no longer drawn.

Expected outcome

  • Steps 3 and 4 should provide some feedback telling the user that this scale is unsupported for this data. Alternatively, the unsupported scales could just be removed from the available options. Or there could be some way for outside code to respond to the error and give the user a descriptive error message.
  • The plot should still display in step 5. Preferably in whatever scale the plot was using before, but I would personally be okay with resetting to a safe default like linear and telling the user that happened.
  • Step 8 should make the whole plot appear, not just the border. Fixing steps 3-5 might make this a non-issue though.

Additional information

I found issue #6852 while looking for information on this one. It had a different exception, but other information in it seems similar to this one. Both involve interactively switching to a scale that doesn't make sense for the data, both result in an exception escaping a slot and being swallowed by Qt, and "inconsistent internal state" seems like an accurate description of what happens to the plot.

It may be that whatever fix was applied for that issue can be adapted to this one. Maybe they're even in the same place.

I noticed that if I plot [2, 3], [2, 3] instead of [1, 2], [1, 2], then steps 3-4 log a warning and don't crash. It seems like it's significant that the values being plotted are on the edge of what the scale supports, rather than being strictly outside it. The plot still disappears in either case though and won't come back when I switch to a valid scale.

Operating system

Windows 10

Matplotlib Version

3.9.2

Matplotlib Backend

qtagg

Python version

3.10.2

Jupyter version

N/A

Installation

pip

@timhoffm
Copy link
Member

timhoffm commented Oct 30, 2024

There is actually a warning on the console:

UserWarning: Data has no values between 0 and 1, and therefore cannot be logit-scaled.

... and a subsequent stack trace.

# 3. Click Apply
# 4. Click OK
# 5. Click Cancel

You can leave out the OK. It doesn't make a difference here.

What is happening is that Apply / OK assign the logit scale and draw the plot. Upon draw, limits are calculated from the data, and the invalid state is detected.

With the subsequent Close you leave the plot in an invalid state. When you reopen the dialog, it must try to reconstruct the parameters from the invalid state. And part of that is is the data interval [0.05, 0.95]. To get going again do

# 7. Change all the Scale dropdowns to `linear`
# 8. Set min 0.95, set max 2.05
# 9. Click OK again

and you are back where you started.

The GUI window is a helper to quickly configure some settings of the plot. I claim we don't have the ambition to add more error handling for invalid settings. The possibility to manually recover must be good enough. Therefore I propose to close without further action.

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

No branches or pull requests

2 participants