OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Not able to show more than 4-5 bar charts using matplotlib in Tkinter

  • Thread starter Thread starter Chandrakanth Reddy
  • Start date Start date
C

Chandrakanth Reddy

Guest
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.

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.
<p>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.</p>
<pre><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()
</code></pre>
<p>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.</p>
 
Top