python tkinter plot points 1

python tkinter plot points

from tkinter import *
from tkinter.ttk import *

import matplotlib
matplotlib.use("TkAgg")

from matplotlib.figure import Figure
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

root = Tk()

figure = Figure(figsize=(5, 4), dpi=100)
plot = figure.add_subplot(1, 1, 1)

plot.plot(0.5, 0.3, color="#C41E3A", marker="o", linestyle="") # Plotting points

x = [ 0.1, 0.2, 0.3 ]
y = [ -0.1, -0.2, -0.3 ]
plot.plot(x, y, color="blue", marker="x", linestyle="")	# Plotting points

canvas = FigureCanvasTkAgg(figure, root)
canvas.get_tk_widget().grid(row=0, column=0)

root.mainloop()	# Running application

Here is what the above code is Doing:
1. We’re creating a Tkinter application.
2. We’re creating a Figure object.
3. We’re adding a subplot to the Figure object.
4. We’re plotting some points on the subplot.
5. We’re creating a FigureCanvasTkAgg object.
6. We’re displaying the FigureCanvasTkAgg object.
7. We’re running the application.

Similar Posts