wxpython embedding? #82
-
Just a question. As EOmaps is based on matplotlib for plotting, is it possible to use it for embedding maps into wxpython based app? Matplotlib plot can be embedded so I imagine EOmaps could be embedded too. Cheers. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Hey, interesting question, thanks for bringing it up! For the dynamic part (e.g. annotations overlays etc.), EOmaps uses a lot of blitting so it very much depends on whether or not the used matplotlib backend already supports it (at the moment If you can provide me with a (ideally very minimalistic) code-snippet on how to embed a basic matplotlib plot I can adapt it to show you how you would use it with EOmaps. |
Beta Was this translation helpful? Give feedback.
-
@domagojhack I converted this issue to a discussion to preserve it for other users as well. I did a quick check using this matplotlib example... At a first glance all seems to work nicely out of the box! 🥳 (I used a fresh environment created with 🐍 source-codefrom matplotlib.backends.backend_wxagg import (
FigureCanvasWxAgg as FigureCanvas,
NavigationToolbar2WxAgg as NavigationToolbar)
from matplotlib.figure import Figure
import numpy as np
import wx
import wx.lib.mixins.inspection as WIT
from eomaps import Maps
class CanvasFrame(wx.Frame):
def __init__(self):
super().__init__(None, -1, 'EOmaps in a wxpython canvas', size=(550, 350))
# -------- create EOmaps map ----------
m = Maps(Maps.CRS.Orthographic(), layer="circles")
m.all.add_feature.preset.coastline()
m.cb.click.attach.annotate(zorder=99)
m.add_feature.preset.ocean()
m2 = m.new_layer("rectangles")
m2.cb.click.attach.annotate(zorder=99)
m2.add_feature.preset.ocean(fc=".25")
n_indicators = 5
colors = "rgbcm"
for i, (r, c) in enumerate(zip(np.logspace(4, 9, n_indicators), colors)):
m.cb.click.attach.mark(permanent=False, shape="geod_circles",
n=100, lw=2, radius=r, fc="none",
ec=c)
m2.cb.click.attach.mark(permanent=False, shape="geod_circles",
n=5, lw=2, radius=r, fc="none",
ec=c)
m.util.layer_selector(loc="upper left", layers=["circles", "rectangles"])
m.subplots_adjust(top=.9, bottom=0.1, left=0, right=1)
# set figure and axes
self.figure = m.figure.f
self.axes = m.ax
# ------------------------------------
self.canvas = FigureCanvas(self, -1, self.figure)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.EXPAND)
self.SetSizer(self.sizer)
self.Fit()
self.add_toolbar() # comment this out for no toolbar
def add_toolbar(self):
self.toolbar = NavigationToolbar(self.canvas)
self.toolbar.Realize()
# By adding toolbar in sizer, we are able to put it at the bottom
# of the frame - so appearance is closer to GTK version.
self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
# update the axes menu on the toolbar
self.toolbar.update()
# Alternatively you could use:
# class App(wx.App):
class App(WIT.InspectableApp):
def OnInit(self):
"""Create the main window and insert the custom frame."""
self.Init()
frame = CanvasFrame()
frame.Show(True)
return True
if __name__ == "__main__":
app = App()
app.MainLoop() |
Beta Was this translation helpful? Give feedback.
@domagojhack I converted this issue to a discussion to preserve it for other users as well.
I did a quick check using this matplotlib example...
At a first glance all seems to work nicely out of the box! 🥳
(I used a fresh environment created with
mamba create -n wx -c conda-forge eomaps wxpython
)🐍 source-code