0

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.

enter image description here

1 Answer 1

1

Put this before the tkinter.mainloop() call:

scrollbar["command"] = canvas.get_tk_widget().xview
canvas.get_tk_widget()["xscrollcommand"] = scrollbar.set
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.