I have little experience how to combine matplotlib with tkinter or pyqt. I need a horizontal scroll bar on the matplotlib chart. I want to zoom the graph horizontally and scroll the graph from the beginning to the end of the data that is loaded from the file. After reviewing the examples, I added a scroll bar. But she's completely unresponsive to the chart.)
And the process doesn't end when I close the window(how to remove not understood, an example taken from here enter link)
import tkinter
from tkinter import *
from matplotlib.backends.backend_tkagg import (
FigureCanvasTkAgg, NavigationToolbar2Tk)
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
root = tkinter.Tk()
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)
canvas = FigureCanvasTkAgg(fig, master=root)
canvas.show()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
toolbar = NavigationToolbar2Tk(canvas, root)
toolbar.update()
canvas.get_tk_widget().pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
scrollbar = tkinter.Scrollbar(master=root, orient=HORIZONTAL)
scrollbar.pack(side=tkinter.BOTTOM, fill=X)
tkinter.mainloop()
After adding a row
scrollbar["command"] = canvas.get_tk_widget().xview
As pointed out- MaxiMouse. The graph scrolls, but not along the entire length. I need the scroll to work on all the data after zooming in. I displayed this at the end of the video.
