-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Subplots aren't updating with fig.canvas.draw_idle()
.
#27216
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
Comments
This is a pretty complicated example to follow. I believe the issue is that you aren't updating the data in the other subplots, so there is no new data for your events to "draw". But, it is a bit unclear what you're expecting to see with this example. I'd suggest trying to narrow it down to just two subplots with minimal data if you can which might show the issue more clearly. |
So in short my code basically highlight lasso selected point with the enter key. And assume there's an index for eacb points, other plots highlight the corresponding points as well, which is done by updating the attribute facecolor of the collection (return object from scatter). I'll try it tmr but what do you mean by data update? Is updating facecolor also a data update to the subplot? |
There is a lot going on in that example, which makes it hard for someone without any context to follow what is going on. I'm just suggesting to boil it down to a simpler example to follow, which might make the analysis easier. I think what is going on is that you aren't updating the data in the other plots how you think you are, but again that is not easy to follow without some added effort of digging into it. Here is a more minimal example that simply swaps facecolors of items in two collections when pressing enter. You should see the blue and red scatter points change every time you hit enter. import matplotlib.pyplot as plt
fig, (ax1, ax2) = plt.subplots(nrows=2)
x = [0, 1, 2]
coll1 = ax1.scatter(x, x, c=["r", "g", "b"])
coll2 = ax2.scatter(x, x, c=["b", "g", "r"])
def accept(event):
match event.key:
case "enter":
print("SWAPPING COLORS")
# swap facecolors
fc1 = coll1.get_facecolors()
fc2 = coll2.get_facecolors()
coll1.set_facecolors(fc2)
coll2.set_facecolors(fc1)
fig.canvas.draw_idle()
case _:
pass
fig.canvas.mpl_connect("key_press_event", accept)
plt.show() |
90% sure that the issue is each of the lasso selectors is using blitting ( |
After comparing your example and mine I found out what I missed was Sorry for my stupid mistakes. Yikes. Thank you very much for your kind help and examples. This would probably be much harder to find out especially without @greglucas example. |
Bug summary
fig.canvas.draw_idle()
in a key event callback doesn't update all subplots (in the example there're 9). No matter what function I used. I've triedfig.canvas.draw()
,plt.pause()
,fig.canvas.flush_events()
.Code for reproduction
Actual outcome
After selecting points from one of the subplots, pressing enter doesn't do anything. Until individual subplots are clicked on, then the plots update properly. But every subplots has to be clicked to update.
Expected outcome
The plots just update themselves after hitting the "Enter" keys.
Additional information
No response
Operating system
macOS Ventura 13.5
Matplotlib Version
3.7.2, 3.8.0 (I tried both)
Matplotlib Backend
MacOSX
Python version
3.11.4
Jupyter version
wasn't using jupyter
Installation
pip
The text was updated successfully, but these errors were encountered: