Tkinter beginner
Tkinter beginner

Reputation: 21

tight_layout() for FigureCanvasTkAgg

I need to add 2 subplots in a canvas. Im trying to use FigureCanvasTkAgg as the plots need to be 3-D interactive. Is there any equvivalent of tight_layout feature available in canvas/FigureCanvasTkAgg ? Tried FigureCanvasTkAgg.tight_layout() and gives error..

f = Figure(figsize=(5,3), dpi=100)

a = f.add_subplot(121)
a.plot([1,2,3,4,5,6,7,8],[5,6,1,3,8,9,3,5])

a1 = f.add_subplot(122)
a1.plot([1,2,3,4,5,6,7,8],[5,6,1,3,8,9,3,5])

canvas = FigureCanvasTkAgg(f, self)
canvas.show()
canvas.tight_layout()
canvas.get_tk_widget().grid(row=20,column=6,sticky=W)

Upvotes: 1

Views: 2462

Answers (3)

Christian Baumann
Christian Baumann

Reputation: 159

Using fig = Figure(tight_layout=True) solved the problem mentioned by @James Brown where the figure is taken to the edge in my case (Windows 10, Python 3.8.3, Matplotlib 3.2.2).

Upvotes: 5

James Brown
James Brown

Reputation: 1

I wanted to set my own setting because tight_layout take it to edge of the frame. I used the toolbar to get my numbers and place this before the canvas.

f.subplots_adjust(left=0.06, bottom=0.16, right=0.90, top=0.92, wspace=0.21, hspace=0.67)

Upvotes: 0

Tkinter beginner
Tkinter beginner

Reputation: 21

Understood with some trials. tight_layout() is associated with the Figure and not the backend.

f.tight_layout() inserted before canvas declaration solves the issue

Upvotes: 0

Related Questions