Skip to content
Snippets Groups Projects
Commit 6e3ca932 authored by Nils Brüggemann's avatar Nils Brüggemann Committed by Fraser William Goldsworth
Browse files

Button to save a figure.

parent 78e9a809
No related branches found
No related tags found
1 merge request!43Allow users to set projection with cartopy projection object
......@@ -149,6 +149,7 @@ class view(object):
self.selected_cmap = tk.StringVar(value=self.colormaps[0])
self.color_limits = tk.StringVar(value="auto") # Default color limits
self.lon_lat_reg_tk = tk.StringVar(value="-180,180,-90,90")
self.save_fig_tk = tk.StringVar(value="./fig.pdf")
self.selected_res = tk.StringVar(value="0.3")
self.selected_proj = tk.StringVar(value="None")
......@@ -217,6 +218,12 @@ class view(object):
command=self.activate_zoom)
self.zoom_button.grid(row=3, column=2)
# save_fig entry
entry = tk.Entry(root, textvariable=self.save_fig_tk)
entry.grid(row=4, column=1)
entry.insert(0, "") # Default value
entry.bind("<Return>", self.save_figure) # Update when pressing Enter
# Variables to store zoom area
self.press_event = None
self.rect = None
......@@ -247,6 +254,13 @@ class view(object):
root.mainloop()
return
# for saving the figure
def save_figure(self, *args):
fpath = self.save_fig_tk.get()
print(f'Saving figure {fpath}')
#plt.savefig(fpath, dpi=300)
plt.savefig(fpath, dpi=300, bbox_inches='tight')
# for zoom
def activate_zoom(self):
"""Activates zooming mode by connecting event handlers."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment