I'm using a matplotlib button to create another plot with a button. However, the second button in the second plot does not work. Could anyone take a look at my code and give me some help?
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import tkinter as tk
from matplotlib.widgets import Button
def next1(event):
print("you clicked here")
def next0(event):
# plt.close('all')
fig, ax = plt.subplots()
rects = ax.bar(range(10), 20*np.random.rand(10))
axnext1 = plt.axes([0.11, 0.05, 0.05, 0.0375])
bnext1 = Button(axnext1, 'Next2')
print(bnext1.label)
bnext1.on_clicked(next1)
plt.show()
fig, ax = plt.subplots()
rects = ax.bar(range(10), 20*np.random.rand(10))
axnext0 = plt.axes([0.11, 0.05, 0.05, 0.0375])
bnext0 = Button(axnext0, 'Next1')
print(bnext0.label)
bnext0.on_clicked(next0)
plt.show()
QCoreApplication::exec: The event loop is already runningand this can be the problem. It runs event loop for first window and it can't run event loop for second window at the same time. it may need to run second plot in separated thread. Or it need to check if you can inform matplotlib that it has to run both windows with one event loop.