0

I am trying to integrate matplotlib into tkinter, this is doable with FigureCanvasTkAgg. However, in my case I want to remove the y axis ticks and then make the graph cover the entire available area (i.e. remove the padding). Removing the y axis was not difficult but I cannot find any information on removing the padding.

If I found a solution (for example: Remove padding from matplotlib plotting) it included using plt.savefig, but saving the image wouldn't help me. I guess I could save the image and display it that way although that would feel pretty hacky. Is there a better way?

My code so far:

import customtkinter 
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib
import numpy as np

root = customtkinter.CTk()
root.geometry('600x500')

# figure
figure = plt.Figure()
ax = figure.add_subplot(111)
ax.yaxis.set_visible(False)

t = np.arange(0, 3, .01)
ax.plot(t, 2 * np.sin(2 * np.pi * t))

# add widget 
canvas = FigureCanvasTkAgg(figure, master=root)
canvas.draw()
canvas.get_tk_widget().pack(fill='both', expand=True)

root.mainloop()
Another_coder
  • 728
  • 1
  • 9
  • 23

0 Answers0