Sunday, 15 March 2015

python - How to update a plot in matplotlib? -


I have issues highlighting this data. I will assign users to the units in the time scale (X-axis) And then call this recalculation and this function plots () . I just do not want to plot the plot, attach another plot to the figure <<> DEF plots (): global vlgaBuffSorted CNTR () result = collections.defaultdict (list) in vlgaBuffSorted d for:. Result [d] [result_list = result.values ​​() f = illustration () graph 1 = f.add_subplot (211) graph2 = f.add_subplot (212, sharex = graph1) For the items in the result_list: TL = [] vgsL = [] VDSL = [] isubL = [] For the word in the dictionary: tL.append (dict ['time']) vgsL.append (dict ['vgs' Graph1.plot (TL, VDSL, 'BO', label = 'one')) graph1.plot (TL, vgsL, etc.) 'RP', label = 'B') graph2.plot (TL, isubL, 'b -', label = 'c') plotCanvas = FigureCanvasTkAgg (f, pltFrame) toolbar = NavigationToolbar2TkAgg (plotCanvas, pltFrame) toolbar.pack Side = down) plotCanvas.get_tk_widget (). Pack (side = top)

You have two options:

  1. Correctly what you are currently doing, but call graph1.clear () and graph2.clear () before replacing it with the most Slow, but the simplest and most robust option.

  2. Instead of copying, you can only update the data of plot objects. You will need to make some changes to your code, but every time you replace things, lots of It should be much faster though, the data you are plotting can not change the size, and if the limit of your data is changing, then you will need to manually reset the X and Y axis boundaries.

    To give an example of another option:

      import matplotlib.pyplot as plt import nppy np x = np.linspace (0, 6 * np.pi, 100) y = np.sin (x) # If you are embedding things in a tkinter plot you probably will not need this ... plt.ion () fig = plt .figure () ax = fig.add_subplot (111) line1, = ax.plot (x, y, 'r-') # gives a tube of line object, thus np.linspace (0, 10 * np. Pi, 500) in the comma for the line: line1.set_ydata (np .n (x + step)) fig.canvas.draw ()    

No comments:

Post a Comment