L
L
LayzyTeh2019-10-09 10:44:40
Python
LayzyTeh, 2019-10-09 10:44:40

Optimizing MathPlotLib Tkinter connection, how to improve speed?

I build a graph using MathPlotLib from a file by points in a loop, and output it to the tkinter window, it takes a long time, and after closing the window, the graph is displayed in the console. What to do

import tkinter
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
w=[]

with open("/home/biotech/Documents/EEG/gur1/sinh0H.txt",'r') as q:
 for i in q.readlines():
 w.append(float(i[:-2]))

t=1/2000

root = tkinter.Tk()
root.wm_title("Embedding in Tk")

fig=plt.figure()
plt.axhline(-0.1,0,2*t*len(w),color="black")
for i in range(len(w)):
 plt.scatter(i*t,w[i],s=1,color="black")

fig.set_size_inches(3,1)
canvas = FigureCanvasTkAgg(fig, master=root) 

canvas.draw()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)

def _quit():
 root.quit() 
 root.destroy() 

tkinter.mainloop()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
longclaps, 2019-10-09
@LayzyTeh

Optimization of the connection, it is the most)
No need to draw the graph point by point.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question