![]() |
plotting data without plt.clear() - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: plotting data without plt.clear() (/thread-23539.html) |
plotting data without plt.clear() - omar_mohsen - Jan-04-2020 I am trying to use a matplotlib module in order to draw data coming from notepad the problem is that I must clear the data every time I parse data in order to plot the data by using plt.clear() now I want to have other alternatives as when I want to zoom in for the graph it returns automatically to the previous plotting which is annoying. The following is considered as a sample of the code f = Figure(figsize=(5,5), dpi=100) a = f.add_subplot(111) def animate(i): pullData = open("sampleText.txt","r").read() dataList = pullData.split('\n') xList = [] yList = [] line,=plt.plot([],[]) for eachLine in dataList: if len(eachLine) > 1: x, y = eachLine.split(',') xList.append(int(x)) yList.append(int(y)) line.set_data(xList,yList) a.clear()##the part that I want to have an alternative code for it a.plot(xList, yList)Thanks for any help |