[Matplotlib-users] Embedding, Drawing, Curser in Tkinter

Thomas Caswell tcaswell at gmail.com
Sat Aug 5 19:58:22 EDT 2017


Stefan,

On a quick skim that does not look wrong.

I would not use globals and have the callbacks be methods on
your BOStrab_Fahrzeugeinschraenkung class.

Tom

On Sat, Aug 5, 2017 at 12:35 PM stefanxfg via Matplotlib-users <
matplotlib-users at python.org> wrote:

> Hello to everyone.
>
> I develop a GUI and i want to embedd Matplotlib in a Tkinter Canvas. Theres
> is no problem until here. But i want to draw the lines and have a curser
> line in the diagram. In the code below i embedd the canvas in the
> INIT-Function.
>
>
>
> class BOStrab_Fahrzeugeinschraenkung:
>         def __init__(self, top=None):
>             ......
>                 self.ya = np.array(ddd)
>                 self.yb = np.array(ddd)
>                 self.z = np.array(ddd)
>
>                 self.canvasframe11 = Frame(self.TPanedwindow4_f2)
>                 self.canvasframe11.place(x=0, y=0, relwidth=1.0,
> relheight=0.95,
> bordermode=INSIDE)
>                 self.canvasframe12 = Frame(self.TPanedwindow4_f2)
>                 self.canvasframe12.place(x=0, rely=0.95, relwidth=1.0,
> bordermode=INSIDE)
>
>                 global ax1
>                 self.fig1 = Figure (figsize=(5,4), dpi=100)
>
>                 self.ax1 = self.fig1.add_subplot(111) #für 2d-Plot
>                 self.ax1.set_title('Definition der LRUGL')
>                 self.ax1.set_xlabel('Breite y [mm]')
>                 self.ax1.set_ylabel('Hoehe z [mm]')
>
>                 self.ax1.axis([-2000,2000,0, 5000])
>                 self.ax1.grid(True)
>                 self.ax1.plot(self.ya,self.z, color='red', linestyle='--',
> marker='')
>                 self.ax1.plot(self.yb,self.z, color='red', linestyle='--',
> marker='')
>
>                 self.canvas1 =
> FigureCanvasTkAgg(self.fig1,self.canvasframe11)
>                 toolbar1 = NavigationToolbar2TkAgg(self.canvas1,
> self.canvasframe12)
>
>                 self.canvas1.get_tk_widget().pack(fill=BOTH, expand=TRUE,
> pady=2, padx=2,
> anchor="n")
>
>
>
> In several examples i saw the drawing in def's and the input for the
> drawing
> from root. So the following code is function then.
>
>
> def onMouseMove(event):
>         ax1.lines = [ax1.lines[0]]
>         ax1.axhline(y=event.ydata, color="k")
>         ax1.axvline(x=event.xdata, color="k")
>
> def updateData():
>         global level1, val1
>         clamp = lambda n, minn, maxn: max(min(maxn, n), minn)
>         yield 1     # FuncAnimation expects an iterator
>
> def visualize(i):
>         lineVal1.set_ydata(val1)
>         return lineVal1
>
>
> My question is. Is my way to embedd the code in Tkinter right? Or its
> better
> to declare the diagram functionalities outside the class and only draw into
> the class?
>
> Best regards from Stefan
>
>
>
> --
> View this message in context:
> http://matplotlib.1069221.n5.nabble.com/Embedding-Drawing-Curser-in-Tkinter-tp48038.html
> Sent from the matplotlib - users mailing list archive at Nabble.com.
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20170805/7252dae8/attachment.html>


More information about the Matplotlib-users mailing list