-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Closed
Description
#!/usr/bin/python3
from gi.repository import Gtk
from matplotlib.figure import Figure
from matplotlib.backends.backend_gtk3cairo import FigureCanvasGTK3Cairo as FigureCanvas
from matplotlib.patches import Rectangle
import signal
class DrawPoints:
'''Creates random points, 2 axis on 1 figure on 1 canvas on init. Allows for drawing and zooming of points.'''
def __init__(self):
self.xs = [0, 500, 1300, 1400, 2000]
self.ys = [0, 1, 7, 6, 3]
self.fig = Figure()
self.ax = self.fig.add_axes ([0, 0, 1, 1], axisbg='None')
self.canvas = FigureCanvas(self.fig)
def on_pick (self, event):
print ("got picked")
def on_press(self, event):
print (self.paths.contains (event))
def draw(self):
'''Draws the ax-subplot'''
self.paths = self.ax.scatter (self.xs, self.ys, picker=True)
self.canvas.mpl_connect ('pick_event', self.on_pick)
self.cidpress = self.canvas.mpl_connect('button_press_event', self.on_press)
signal.signal (signal.SIGINT, signal.SIG_DFL)
window = Gtk.Window()
window.connect("delete-event", Gtk.main_quit)
window.set_default_size(1000, 600)
box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL)
window.add(box)
scrolled = Gtk.ScrolledWindow ()
points = DrawPoints()
points.draw()
scrolled.add (points.canvas)
box.pack_start(scrolled, True, True, 0)
window.show_all()
Gtk.main()