Created
April 11, 2020 11:52
-
-
Save barsv/3674b7eb2fb348ca6ac483c348424d6f to your computer and use it in GitHub Desktop.
How to put matplot lib graph into tkinter window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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