Python Forum
Dynamic graph matplotlib - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: Dynamic graph matplotlib (/thread-18422.html)



Dynamic graph matplotlib - quant7 - May-16-2019

I draw a lot of data in matplotlib. So I want to make a widget that adjusts the scale horizontally with automatic adjustment vertically.
And after adjusting the zoom use the scroll bar to view the entire graph. Is it possible to do this in matplotlib?
C# is much more complicated than Python, but I was able to do it with it. But in Python I can not do it, I have to study several libraries(Tkinter, PyQt, matplotlib). And it is not clear whether I'm on the right path?
Asked questions on "stackoverflow" and received nothing intelligible as the answer.


from tkinter import *
from matplotlib.backends.backend_tkagg import (
    FigureCanvasTkAgg, NavigationToolbar2Tk)
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

x = pd.read_csv('file.txt',index_col='DATE',parse_dates=True,infer_datetime_format=True)
z = x.iloc[:, 3].values
N = len(z)
ind = np.arange(N)
fig, ax = plt.subplots()
ax.plot(ind, z)

root = Tk()
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
canvas.show()

toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()

scrollbar = tkinter.Scrollbar(master=root, orient=HORIZONTAL)
scrollbar.pack(fill=X)

scrollbar["command"] = canvas.get_tk_widget().xview

tkinter.mainloop()

And it's not the first time I come across in Python that no one knows the answer)

If you need something non-standard, then in Python it is difficult to do....


RE: Dynamic graph matplotlib - quant7 - May-17-2019

I was able to program the Slider as in the link.Slider
I posted a GIF how it turned out [Image: 7g80wZg]
But still want to do so in tkinter.