简体   繁体   中英

How to control individual matplotlib subplots' x-axis scale in real time using tkinter?

First time posting to stackoverflow so i'll try to get this right...

I'm running a data acquisition module in python who's input data stream is the output of a different python module. Tkinter sliders are used to control: the scale of the x-axis of the plot (which is plotting the incoming data), and 'generation speed':

for axisnum in range( len( subplots ) ):
    wScale  = Tkinter.Scale( master = roots[root],
                             label  = "View Width on Plot %s:" % ( axisnum ),
                             from_  = 3, to = 1000,
                             orient = Tkinter.HORIZONTAL,
                             sliderlength   = 30,
                             length = subplots[axisnum].get_frame().get_window_extent().width,
                             )
    wScale2 = Tkinter.Scale( master = roots[root],
                             label  = "Generation Speed for Plot %s:" % ( axisnum ),
                             from_  = 1, to = 200,
                             orient = Tkinter.HORIZONTAL,
                             sliderlength   = 30,
                             length = subplots[axisnum].get_frame().get_window_extent().width
                             )
    wScale2.pack( side = Tkinter.BOTTOM )
    wScale.pack(  side = Tkinter.BOTTOM )
    wScale.set(   100 )
    wScale2.set(  wScale2['to'] - 3 )

The problem is that, though this creates all 'n' pairs of slider widgets on the canvas only the first is actually active and moreover acts as a 'master slider' controlling all 'n' subplots simultaneously.

Slight modifications have led to the 'x and y data must be same length' being raised.

So any suggestions on how I can create tkinter sliders which control the scale of the x-axis of individual subplots on a single figure?

Update

Perhaps the problem could be in my RealtimePlotter?

Note dsets[Figure][subs][data] will get you the data points for a specific subplot; subs should typically be left at '0'.

    def RealtimePlotter():
      global dsets, wScalesList, wScales2List
      for i in range(len(Figures_List)):
          for Scale in wScalesList:
             Samples = min(len(dsets[i][0][0]),Scale[0].get())
             XAxis = pylab.arange(len(dsets[i][0][0])-Samples, 
                                  len(dsets[i][0][0], 1
                                  )
             for t in range(len(linenum)-1):
             #we choose lineax and axnum[1] because [0] is just the figure number
                 (lineax[t+1])[i].set_data(XAxis,pylab.array(dsets[i][0][t][-Samples:])
                 (axinfo[t+1]).axis([XAxis.min(),Xaxis.max(),-1.5,1.5])
          for canvas in range(len(canvasList)):
              canvasList[canvas].draw()
          for root in range(len(roots)):
              roots[root].after(100,RealtimePlotter) 

There is no problem with the example below so there must be something in your code that I am not able to duplicate. When you say "canvas" are the sliders on a canvas object or is that just a figure of speech. Also, which type of object is roots[root].

"only the first is actually active and moreover acts as a 'master slider' controlling all 'n' subplots simultaneously" I think that the only way this is possible is if they all point to the same object.

import Tkinter
root=Tkinter.Tk()
root.geometry("225x150")

for slide_length in (200, 150):
    wScale  = Tkinter.Scale( master = root,
                         label  = "View Width on Plot ",
                         from_  = 3, to = 1000,
                         orient = Tkinter.HORIZONTAL,
                         sliderlength   = 30,
                         length = slide_length)
    wScale.pack(side = Tkinter.BOTTOM)
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM