You should use matplotlib.figure.Figure
instead of plt.figure
when embedding a matplotlib
graph with tkinter
. Also the sequence of Figure
, canvas
and ax
creation matters:
def button_add():
...
# Plot
fig = Figure()
canvas = FigureCanvasTkAgg(fig, w)
canvas.draw()
ax = fig.add_subplot(111, projection="3d")
ax.plot(xs, ys, zs, lw=0.5)
ax.set_xlabel("X Axis")
ax.set_ylabel("Y Axis")
ax.set_zlabel("Z Axis")
ax.set_title("Lorenz Attractor")
toolbar = NavigationToolbar2Tk(canvas, w)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
...
CLICK HERE to find out more related problems solutions.