Skip to content
Snippets Groups Projects

Draft: cartopy projections

Closed Fraser William Goldsworth requested to merge m301014/pyicon:master into master
1 file
+ 67
0
Compare changes
  • Side-by-side
  • Inline
+ 67
0
@@ -164,6 +164,25 @@ class view(object):
res_menu.grid(row=3, column=0)
res_menu.bind("<<ComboboxSelected>>", self.make_new_axis)
# Button to activate zoom mode
self.zoom_button = ttk.Button(root, text="Enable Zoom", command=self.activate_zoom)
self.zoom_button.grid(row=3, column=2)
# Variables to store zoom area
self.press_event = None
self.rect = None
# Variables to store zoom area
self.press_event = None
self.rect = None
# proj entry
print('Setup proj dropdown')
res_menu = ttk.Combobox(root, textvariable=self.selected_proj,
values=self.proj_all, state="readonly")
res_menu.grid(row=3, column=3)
res_menu.bind("<<ComboboxSelected>>", self.make_new_axis)
# initial plot
self.plot_data()
self.canvas.draw()
@@ -173,6 +192,54 @@ class view(object):
root.mainloop()
return
# for zoom
def activate_zoom(self):
"""Activates zooming mode by connecting event handlers."""
self.cid_press = self.canvas.mpl_connect("button_press_event", self.on_press)
self.cid_release = self.canvas.mpl_connect("button_release_event", self.on_release)
self.cid_motion = self.canvas.mpl_connect("motion_notify_event", self.on_motion)
# for zoom
def on_press(self, event):
"""Stores the initial click position."""
if event.xdata is not None and event.ydata is not None:
self.press_event = (event.xdata, event.ydata)
self.rect = self.ax.add_patch(plt.Rectangle(self.press_event, 0, 0, fill=False, color="red", linestyle="dashed"))
self.canvas.draw()
# for zoom
def on_motion(self, event):
"""Updates the rectangle while dragging."""
if self.press_event and event.xdata is not None and event.ydata is not None:
x0, y0 = self.press_event
width = event.xdata - x0
height = event.ydata - y0
self.rect.set_width(width)
self.rect.set_height(height)
self.canvas.draw()
# for zoom
def on_release(self, event):
"""Zooms into the selected rectangle and removes it."""
if self.press_event and event.xdata is not None and event.ydata is not None:
x0, y0 = self.press_event
x1, y1 = event.xdata, event.ydata
# Ensure correct ordering of coordinates
self.ax.set_xlim(min(x0, x1), max(x0, x1))
self.ax.set_ylim(min(y0, y1), max(y0, y1))
# Remove the rectangle and redraw
self.rect.remove()
self.rect = None
self.press_event = None
self.canvas.draw()
# Disable event handlers after zooming
self.canvas.mpl_disconnect(self.cid_press)
self.canvas.mpl_disconnect(self.cid_release)
self.canvas.mpl_disconnect(self.cid_motion)
def load_data(self):
print('opening dataset')
mfdset_kwargs = dict(
Loading