Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Zoom in NavigationToolbar2Tk stops working after updating the canvas figure. #20159

Closed
Milestone
@kopytjuk

Description

@kopytjuk

Bug report

Bug summary

After updatingcanvas.figure with a new figure (and successivecanvas.draw() call zoom does not work in3.4.1 release. The same code works for3.3.4.

Code for reproduction

# adapted from# https://matplotlib.org/stable/gallery/user_interfaces/embedding_in_tk_sgskip.htmlimporttkinterfrommatplotlib.backends.backend_tkaggimport (FigureCanvasTkAgg,NavigationToolbar2Tk)# Implement the default Matplotlib key bindings.frommatplotlib.backend_basesimportkey_press_handlerfrommatplotlib.figureimportFigurefrommatplotlibimport__version__importnumpyasnpprint("matplotlib",__version__)root=tkinter.Tk()root.wm_title("Embedding in Tk")fig=Figure(figsize=(5,4),dpi=100)t=np.arange(0,3,.01)fig.add_subplot().plot(t,2*np.sin(2*np.pi*t))canvas=FigureCanvasTkAgg(fig,master=root)# A tk.DrawingArea.canvas.draw()# pack_toolbar=False will make it easier to use a layout manager later on.toolbar=NavigationToolbar2Tk(canvas,root,pack_toolbar=False)toolbar.update()##### Change !!!# second figuresecond_fig=Figure(figsize=(5,4),dpi=100)t=np.arange(0,4,.01)second_fig.add_subplot().plot(t,2*np.sin(2*np.pi*t))canvas.figure=second_figtoolbar.update()canvas.draw()##### !!!canvas.mpl_connect("key_press_event",lambdaevent:print(f"you pressed{event.key}"))canvas.mpl_connect("key_press_event",key_press_handler)button=tkinter.Button(master=root,text="Quit",command=root.quit)# Packing order is important. Widgets are processed sequentially and if there# is no space left, because the window is too small, they are not displayed.# The canvas is rather flexible in its size, so we pack it last which makes# sure the UI controls are displayed as long as possible.button.pack(side=tkinter.BOTTOM)toolbar.pack(side=tkinter.BOTTOM,fill=tkinter.X)canvas.get_tk_widget().pack(side=tkinter.TOP,fill=tkinter.BOTH,expand=1)tkinter.mainloop()

Matplotlib version

  • Operating system: ubuntu
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.1
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.8.5
  • Jupyter version (if applicable):
  • Other libraries:

Installed from pip.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp