Skip to content

Instantly share code, notes, and snippets.

@barsv
Created April 11, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barsv/3674b7eb2fb348ca6ac483c348424d6f to your computer and use it in GitHub Desktop.
Save barsv/3674b7eb2fb348ca6ac483c348424d6f to your computer and use it in GitHub Desktop.
How to put matplot lib graph into tkinter window
# minimal example on how to put matplot lib graph into tkinter window
import tkinter as tk
import matplotlib.backends.backend_tkagg as tka
from matplotlib.figure import Figure
import numpy as np
win = tk.Tk()
fig = Figure()
canvas = tka.FigureCanvasTkAgg(fig, win)
toolbar = tka.NavigationToolbar2Tk(canvas, win)
canvas.get_tk_widget().pack()
ax = fig.add_subplot()
ax.scatter(1, 1)
ax.scatter(2, 4)
def on_click():
ax.scatter(3, 9)
canvas.draw()
button = tk.Button(win, text="add", command=on_click)
button.pack(side=tk.BOTTOM)
win.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment