I am trying to display 4-5 matplotlib bar chart in a Tkinter window. But some how only 3 are fitting inside the frame. Please find the below code.
import tkinter as tk
from matplotlib.backends.backend_tkagg import (FigureCanvasTkAgg, NavigationToolbar2Tk)
from matplotlib.figure import Figure
import matplotlib.
# --- main ---
x = [1, 2, 3, 4]
y = [1, 2, 3, 4]
AS = [10 / 2 ** 0]
# ---
root = tk.Tk()
root.geometry("1000x1000")
root.title("eggs")
# ---
frame_top = tk.Frame(root)
frame_top.pack(fill='both', expand=True)
fig = Figure(dpi=100) # figsize=(10, 6),
fig.add_subplot(111).plot(x, y)
# fig.add_subplot(111).plot(AS)
canvas = FigureCanvasTkAgg(fig, master=frame_top) # A tk.DrawingArea.
canvas.draw()
canvas.get_tk_widget().pack(side="left",fill='both', expand=True)
fig1 = Figure(dpi=100) # figsize=(10, 6),
fig1.add_subplot(111).plot(x, y)
# fig.add_subplot(111).plot(AS)
canvas1 = FigureCanvasTkAgg(fig1, master=frame_top) # A tk.DrawingArea.
canvas1.draw()
canvas1.get_tk_widget().pack(side="left",fill='both', expand=True)
fig2 = Figure(dpi=100) # figsize=(10, 6),
fig2.add_subplot(111).plot(x, y)
# fig.add_subplot(111).plot(AS)
canvas2 = FigureCanvasTkAgg(fig2, master=frame_top) # A tk.DrawingArea.
canvas2.draw()
canvas2.get_tk_widget().pack(side="left",fill='both', expand=True)
fig3 = Figure(dpi=100) # figsize=(10, 6),
fig3.add_subplot(111).plot(x, y)
# fig.add_subplot(111).plot(AS)
canvas3 = FigureCanvasTkAgg(fig3, master=frame_top) # A tk.DrawingArea.
canvas3.draw()
canvas3.get_tk_widget().pack(side="left",fill='both', expand=True)
# toolbar = NavigationToolbar2Tk(canvas, frame_top)
# toolbar.update()
# tool = tk.Button(toolbar, text="my tool")
# tool.pack(side='left')#, fill='x', expand=True)
root.mainloop()
I tried to use horizontal scroll bar to but somehow it is also not working. If there are any other suggestions and any other way to show multiple bar charts inside and a frame.
New contributor
Chandrakanth Reddy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.