pb avec NavigationToolbar2TkAgg
Bonsoir,
J'avais un programme (de wiztricks je crois) qui fonctionnait mais qui me délivre un message d'erreur.
On dirait que matplotlib a évolué ou que je n'ai pas tout bien installé. Des idées ?
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| import matplotlib
matplotlib.use('TkAgg')
import math
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
from matplotlib.figure import Figure
import tkinter as tk
from tkinter.constants import TOP, BOTH, BOTTOM, LEFT
def figure_create(master=None):
figure = Figure(figsize=(5,4), dpi=100)
axe = figure.add_subplot(111)
canvas = FigureCanvasTkAgg(figure, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
toolbar = NavigationToolbar2TkAgg( canvas, root )
toolbar.update()
canvas._tkcanvas.pack(side=TOP, fill=BOTH, expand=1)
figure._toolbar = toolbar
return figure
plotShift = 0
def figure_draw(figure):
global plotShift
axe = figure.axes[0]
xVals = range(100)
axe.plot(xVals, [math.sin(x + plotShift) for x in xVals])
figure.canvas.draw()
plotShift += 10
def figure_clear(figure):
axe = figure.axes[0]
axe.clear()
figure.canvas.draw()
def figure_hide(figure):
figure.canvas.get_tk_widget().pack_forget()
def figure_show(figure):
figure.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)
root = tk.Tk()
root.wm_title("Embedding in TK")
figure = figure_create(master=root)
frame = tk.Frame(root)
tk.Button(frame, text='draw', command=lambda f=figure: figure_draw(f)).pack(side=LEFT)
tk.Button(frame, text='clear', command=lambda f=figure: figure_clear(f)).pack(side=LEFT)
tk.Button(frame, text='show', command=lambda f=figure: figure_show(f)).pack(side=LEFT)
tk.Button(frame, text='hide', command=lambda f=figure: figure_hide(f)).pack(side=LEFT)
frame.pack(side=BOTTOM)
tk.mainloop() |
Le message d'erreur :
Code:
1 2 3
| from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
ImportError: cannot import name 'NavigationToolbar2TkAgg' |