Contents:
To use the whole potential of EOmaps with the awesome Spyder IDE , the plot-settings must be adjusted to ensure that matplotlib
plots remain interactive.
- By default, plots are rendered as static images into the "plots-pane"... to avoid this and create interactive
matplotlib
widgets instead, go to the preferences and set the "Graphics backend" to "Automatic" :
The PyCharm IDE automatically registers its own matplotlib backend which (for some unknown reason) freezes on interactive plots.
To my knowledge there are 2 possibilities to force pycharm
to use the original matplotlib
backends:
- 🚲 The "manual" way:
Add the following lines to the start of each script:
(for more info and alternative backends see matplotlib docs)import matplotlib matplotlib.use("Qt5Agg")
- 🚗 The "automatic" way:
Go to the preferences and add the aforementioned lines to the "Starting script"
(to ensure that thematplotlib
backend is always set prior to running a script)
In addition, if you use a commercial version of PyCharm, make sure to disable "Show plots in tool window" in the Python Scientific preferences since it forces plots to be rendered as static images.
To get the most out of EOmaps in Jupyter Notebooks, use jupyter lab together with the ipympl (widget
) backend.
- To install, use
conda install -c conda-forge ipympl
Once it's installed, use the command %matplotlib widget
at the start of the code to activate the backend.
To use the companion_widget
in backends other than Qt
the Qt event-loop must be integrated. This can be done with the %gui qt
command.
%matplotlib widget
%gui qt
from eomaps import Maps
m = Maps()
m.add_feature.preset("coastline", "ocean")
For classical notebooks, there's also the nbagg
backend provided by matplotlib
- To use it, simply execute the magic
%matplotlib notebook
before starting to plot.
And you can also use the magic %matplotlib qt
to use the default qt5agg
backend.
- This way the plots will NOT be embedded in the notebook, they show up as popups.
Note
It is possible to plot static snapshots of the current state of a map to a Jupyter Notebook irrespective of the used backend by using m.snapshot(), e.g.:
m = Maps()
m.add_feature.preset.coastline()
m.snapshot()
Checkout the matplotlib doc for more info!
The best way to record interactions on a EOmaps map is with the free and open source ScreenToGif software.
All animated gifs in this documentation have been created with this awesome piece of software.
Changes between EOmaps v3.x and EOmaps v4.0:
- the following properties and functions have been removed:
- ❌
m.plot_specs.
- ❌
m.set_plot_specs()
- arguments are now directly passed to relevant functions:
m.plot_map()
,m.add_colorbar()
andm.set_data()
- ❌
- 🔶
m.set_shape.voroni_diagram()
is renamed tom.set_shape.voronoi_diagram()
- 🔷 custom callbacks are no longer bound to the Maps-object
the call-signature of custom callbacks has changed to:
def cb(self, *args, **kwargs)
>>def cb(*args, **kwargs)
Porting a script from v3.x to v4.x is quick and easy and involves the following steps:
Search your script for all occurrences of the words
.plot_specs
and.set_plot_specs(
, move the affected arguments to the correct functions (and remove the calls once you're done):vmin
,vmax
alpha
andcmap
are now set in
m.plot_map(vmin=..., vmax=..., alpha=..., cmap=...)
histbins
,label
,tick_precision
anddensity
are now set in
m.add_colorbar(histbins=..., label=..., tick_precision=..., density=...)
cpos
andcpos_radius
are now (optionally) set in
m.set_data(data, x, y, cpos=..., cpos_radius=...)
- Search your script for all occurrences of the words
xcoord
andycoord
and replace them withx
andy
- ONLY if you used voronoi diagrams:
- search in your script for all occurrences of the word
voroni_diagram
and replace it withvoronoi_diagram
- ONLY if you used custom callback functions:
- the first argument of custom callbacks is no longer identified as the
Maps
object.- if you really need access to the
Maps
object within the callback, pass it as an explicit argument!
EOmaps v3.x:
m = Maps()
m.set_data(data=..., xcoord=..., ycoord=...)
m.set_plot_specs(vmin=1, vmax=20, cmap="viridis", histbins=100, cpos="ul", cpos_radius=1)
m.set_shape.voroni_diagram()
m.add_colorbar()
m.plot_map()
# ---------------------------- custom callback signature:
def custom_cb(m, asdf=1):
print(asdf)
m.cb.click.attach(custom_cb)
EOmaps v4.x:
m = Maps()
m.set_data(data=..., x=..., y=..., cpos="ul", cpos_radius=1)
m.plot_map(vmin=1, vmax=20, cmap="viridis")
m.set_shape.voronoi_diagram()
m.add_colorbar(histbins=100)
# ---------------------------- custom callback signature:
def custom_cb(**kwargs, asdf=None):
print(asdf)
m.cb.click.attach(custom_cb, asdf=1)
Note: if you really need access to the maps-object within custom callbacks, simply provide it as an explicit argument!
def custom_cb(**kwargs, m=None, asdf=None):
...
m.cb.click.attach(custom_cb, m=m, asdf=1)
- 🔶 Starting with EOmaps v6.0 multiple calls to
m.plot_map()
on the same Maps-object completely remove (and replace) the previous dataset!
(use a new Maps-object on the same layer for datasets that should be visible at the same time!) - 🔶 WebMap services are no longer re-fetched by default when exporting images with
m.savefig()
To force a re-fetch of WebMap services prior to saving the image at the desired dpi, usem.savefig(refetch_wms=True)
(seem.refetch_wms_on_size_change()
for more details) - 🔷
m.add_gdf
now uses only valid geometries
(to revert to the old behavior, use:m.add_gdf(..., only_valid=False)
) - 🔷 the order at which multi-layers are combined now determines the stacking of the artists
m.show_layer("A|B")
plots all artists of the layer"A"
on top of the layer"B"
- the ordering of artists inside a layer is determined by their
zorder
(e.g.m.plot_map(zorder=123)
)
- ❌ the
m.figure
accessor has been removed!- Use
m.ax
,m.f
,m.colorbar.ax_cb
,m.colorbar.ax_cb_plot
instead
- Use
- ❌ kwargs for
m.plot_map(...)
"coastlines"
usem.add_feature.preset.coastline()
instead
❌ kwargs for
m.set_data(...)
"in_crs"
use"crs"
instead"xcoord"
use"x"
instead"ycoord"
use"y"
instead
- ❌ kwargs for
Maps(...)
"parent"
... no longer needed"gs_ax"
use"ax"
instead
- ❌ kwargs for
m.new_inset_maps(...)
"edgecolor"
and"facecolor"
useboundary=dict(ec=..., fc=...)
instead
- ❌ kwargs for
m.add_colorbar(...)
"histbins"
use"hist_bins"
instead"histogram_size"
use"hist_size"
instead"density"
use"hist_kwargs=dict(density=...)"
instead"top", "bottom", "left", "right"
usemargin=dict(top=..., bottom=..., left=..., right=...)
instead"add_extend_arrows"
- ❌
m.indicate_masked_points()
has been removed, usem.plot_map(indicate_masked_points=True)
instead - ❌
m.shape.get_transformer
is now a private (e.g.m.shape._get_transformer
) - ❌
m.shape.radius_estimation_range
is now a private (e.g.m.shape._radius_estimation_range
)
⚠️ A lot of internal functions and classes have been re-named to better follow PEP8 naming conventions. While this should not interfere with the public API, more extensive customizations might need to be adjusted with respect to the new names.If you encounter any problems, feel free to open an issue , and I'll see what I can do!
- For example: the module _shapes.py is now called shapes.py and the class shapes is now called Shapes
⚠️ The use ofm.set_data_specs(...)
is depreciated. Usem.set_data(...)
instead!- Figure export routines have been completely re-worked (but should result in the exact same output as in v6.x)