diff --git a/examples/animation/simple_anim.py b/examples/animation/simple_anim.py index 417aa5f36709..457bfba12fed 100644 --- a/examples/animation/simple_anim.py +++ b/examples/animation/simple_anim.py @@ -16,7 +16,7 @@ def animate(i): - line.set_ydata(np.sin(x + i/10.0)) # update the data + line.set_ydata(np.sin(x + i / 100)) # update the data return line, @@ -25,6 +25,6 @@ def init(): line.set_ydata(np.ma.array(x, mask=True)) return line, -ani = animation.FuncAnimation(fig, animate, np.arange(1, 200), init_func=init, - interval=25, blit=True) +ani = animation.FuncAnimation( + fig, animate, init_func=init, interval=2, blit=True) plt.show() diff --git a/examples/user_interfaces/embedding_in_tk2_sgskip.py b/examples/user_interfaces/embedding_in_tk2_sgskip.py deleted file mode 100644 index 89be179d4058..000000000000 --- a/examples/user_interfaces/embedding_in_tk2_sgskip.py +++ /dev/null @@ -1,49 +0,0 @@ -""" -================ -Embedding In Tk2 -================ - -""" -import matplotlib -matplotlib.use('TkAgg') - -from numpy import arange, sin, pi -from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg -from matplotlib.figure import Figure - -import sys -if sys.version_info[0] < 3: - import Tkinter as Tk -else: - import tkinter as Tk - - -def destroy(e): - sys.exit() - -root = Tk.Tk() -root.wm_title("Embedding in TK") - - -f = Figure(figsize=(5, 4), dpi=100) -a = f.add_subplot(111) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) - -a.plot(t, s) -a.set_title('Tk embedding') -a.set_xlabel('X axis label') -a.set_ylabel('Y label') - - -# a tk.DrawingArea -canvas = FigureCanvasTkAgg(f, master=root) -canvas.show() -canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) - -canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) - -button = Tk.Button(master=root, text='Quit', command=sys.exit) -button.pack(side=Tk.BOTTOM) - -Tk.mainloop() diff --git a/examples/user_interfaces/embedding_in_tk_sgskip.py b/examples/user_interfaces/embedding_in_tk_sgskip.py index 8def18952312..bee6bb050281 100644 --- a/examples/user_interfaces/embedding_in_tk_sgskip.py +++ b/examples/user_interfaces/embedding_in_tk_sgskip.py @@ -4,38 +4,27 @@ =============== """ -import matplotlib -matplotlib.use('TkAgg') - -from numpy import arange, sin, pi -from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg -# implement the default mpl key bindings -from matplotlib.backend_bases import key_press_handler +from six.moves import tkinter as Tk +from matplotlib.backends.backend_tkagg import ( + FigureCanvasTkAgg, NavigationToolbar2TkAgg) +# Implement the default Matplotlib key bindings. +from matplotlib.backend_bases import key_press_handler from matplotlib.figure import Figure -import sys -if sys.version_info[0] < 3: - import Tkinter as Tk -else: - import tkinter as Tk - -root = Tk.Tk() -root.wm_title("Embedding in TK") +import numpy as np -f = Figure(figsize=(5, 4), dpi=100) -a = f.add_subplot(111) -t = arange(0.0, 3.0, 0.01) -s = sin(2*pi*t) - -a.plot(t, s) +root = Tk.Tk() +root.wm_title("Embedding in Tk") +fig = Figure(figsize=(5, 4), dpi=100) +t = np.arange(0, 3, .01) +fig.add_subplot(111).plot(t, 2 * np.sin(2 * np.pi * t)) -# a tk.DrawingArea -canvas = FigureCanvasTkAgg(f, master=root) -canvas.show() +canvas = FigureCanvasTkAgg(fig, master=root) # A tk.DrawingArea. +canvas.draw() canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) toolbar = NavigationToolbar2TkAgg(canvas, root) @@ -43,11 +32,12 @@ canvas._tkcanvas.pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) -def on_key_event(event): - print('you pressed %s' % event.key) +def on_key_press(event): + print("you pressed {}".format(event.key)) key_press_handler(event, canvas, toolbar) -canvas.mpl_connect('key_press_event', on_key_event) + +canvas.mpl_connect("key_press_event", on_key_press) def _quit(): @@ -55,9 +45,10 @@ def _quit(): root.destroy() # this is necessary on Windows to prevent # Fatal Python Error: PyEval_RestoreThread: NULL tstate -button = Tk.Button(master=root, text='Quit', command=_quit) + +button = Tk.Button(master=root, text="Quit", command=_quit) button.pack(side=Tk.BOTTOM) Tk.mainloop() -# If you put root.destroy() here, it will cause an error if -# the window is closed with the window manager. +# If you put root.destroy() here, it will cause an error if the window is +# closed with the window manager. diff --git a/lib/matplotlib/backends/backend_tkagg.py b/lib/matplotlib/backends/backend_tkagg.py index 85d32067f4e2..7a36dc6febd4 100644 --- a/lib/matplotlib/backends/backend_tkagg.py +++ b/lib/matplotlib/backends/backend_tkagg.py @@ -231,7 +231,7 @@ def resize(self, event): master=self._tkcanvas, width=int(width), height=int(height)) self._tkcanvas.create_image(int(width/2),int(height/2),image=self._tkphoto) self.resize_event() - self.show() + self.draw() # a resizing will in general move the pointer position # relative to the canvas, so process it as a motion notify @@ -307,10 +307,12 @@ def draw(self): self._master.update_idletasks() def blit(self, bbox=None): - tkagg.blit(self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2) + tkagg.blit( + self._tkphoto, self.renderer._renderer, bbox=bbox, colormode=2) self._master.update_idletasks() - show = draw + show = cbook.deprecated("2.2", name="FigureCanvasTkAgg.show", + alternative="FigureCanvasTkAgg.draw")(draw) def draw_idle(self): 'update drawing area only if idle' @@ -536,6 +538,8 @@ def resize(self, width, height=None): # when a single parameter is given, consider it as a event if height is None: + cbook.warn_deprecated("2.2", "FigureManagerTkAgg.resize now takes " + "width and height as separate arguments") width = width.width else: self.canvas._tkcanvas.master.geometry("%dx%d" % (width, height)) @@ -555,8 +559,6 @@ def destroy(*args): Gcf.destroy(self._num) self.canvas._tkcanvas.bind("", destroy) self.window.deiconify() - # anim.py requires this - self.window.update() else: self.canvas.draw_idle() # Raise the new window. @@ -738,8 +740,8 @@ def configure_subplots(self): window = Tk.Toplevel() canvas = FigureCanvasTkAgg(toolfig, master=window) toolfig.subplots_adjust(top=0.9) - canvas.tool = SubplotTool(self.canvas.figure, toolfig) - canvas.show() + canvas.tool = SubplotTool(self.canvas.figure, toolfig) + canvas.draw() canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) window.grab_set() @@ -1021,7 +1023,7 @@ def init_window(self): canvas = FigureCanvasTkAgg(toolfig, master=self.window) toolfig.subplots_adjust(top=0.9) _tool = SubplotTool(self.figure, toolfig) - canvas.show() + canvas.draw() canvas.get_tk_widget().pack(side=Tk.TOP, fill=Tk.BOTH, expand=1) self.window.protocol("WM_DELETE_WINDOW", self.destroy)