Skip to content

Commit

Permalink
Merge pull request #217 from raphaelquast/v7.3.3
Browse files Browse the repository at this point in the history
Merge for v7.3.3
  • Loading branch information
raphaelquast authored Dec 20, 2023
2 parents c373e04 + ab2452d commit a285226
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 35 deletions.
2 changes: 1 addition & 1 deletion eomaps/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "7.3.2"
__version__ = "7.3.3"
16 changes: 14 additions & 2 deletions eomaps/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,9 @@ def set_hist_size(self, size=None):
_TransformedBoundsLocator(cbpos, self._ax.transAxes)
)

# re-fetch ALL layers (since axes-positions have changed!)
self._m.BM._refetch_layer("all")

if self._hist_size > 0.0001:
self.ax_cb_plot.set_visible(True)

Expand Down Expand Up @@ -889,7 +892,14 @@ def check_data_updated(*args, **kwargs):
self._set_extend(z_data)

if self._out_of_range_vals == "mask":
z_data = z_data[(z_data >= self._vmin) & (z_data <= self._vmax)]
data_range_mask = (z_data >= self._vmin) & (z_data <= self._vmax)
z_data = z_data[data_range_mask]

# make sure that histogram weights are masked accordingly if provided
if "weights" in self._hist_kwargs:
self._hist_kwargs["weights"] = self._hist_kwargs["weights"][
data_range_mask
]

# make sure the norm clips with respect to vmin/vmax
# (only clip if either vmin or vmax is not None)
Expand All @@ -916,7 +926,9 @@ def _plot_colorbar(self):
horizontal = self._orientation == "horizontal"
n_cmap = plt.cm.ScalarMappable(cmap=self._cmap, norm=self._norm)

self.cb = plt.colorbar(
# avoid using "plt.colorbar" since it might not properly recognize
# the associated figure (e.g. plt.gcf() might point somewhere else)!
self.cb = self._m.f.colorbar(
n_cmap,
cax=self.ax_cb,
extend=self._extend,
Expand Down
48 changes: 22 additions & 26 deletions eomaps/eomaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ def _handle_backends():
"To change, use Maps.config(use_interactive_mode=True/False)."
)

# check if we are in an ipython console using the inline-backend.
# If yes, put a snapshot of the map into the active cell on each update
if BlitManager._snapshot_on_update is None:
try:
__IPYTHON__
except NameError:
BlitManager._snapshot_on_update = False
else:
active_backend = plt.get_backend()
# print a snapshot to the active ipython cell in case the
# inline-backend is used
if active_backend in ["module://matplotlib_inline.backend_inline"]:
BlitManager._snapshot_on_update = True


# hardcoded list of available mapclassify-classifiers
# (to avoid importing it on startup)
Expand Down Expand Up @@ -3356,6 +3342,12 @@ def show_layer(self, *args, clear=True):
self.BM.bg_layer = name
self.BM.update()

# plot a snapshot to jupyter notebook cell if inline backend is used
if not self.BM._snapshot_on_update and plt.get_backend() in [
"module://matplotlib_inline.backend_inline"
]:
self.snapshot(clear=clear)

def show(self, clear=True):
"""
Show the map (only required for non-interactive matplotlib backends).
Expand Down Expand Up @@ -3386,7 +3378,7 @@ def show(self, clear=True):
# print a snapshot to the active ipython cell in case the
# inline-backend is used
if active_backend in ["module://matplotlib_inline.backend_inline"]:
self.BM.update(clear_snapshot=clear)
self.snapshot(clear=clear)
else:
plt.show()

Expand Down Expand Up @@ -3425,6 +3417,11 @@ def snapshot(self, *layer, transparent=False, clear=False):
>>> m.snapshot("base", ("ocean", .5), transparent=True)
"""
if getattr(self, "_snapshotting", False):
# this is necessary to avoid recursions with show_layer
# in jupyter-notebook inline backend
return

try:
self._snapshotting = True

Expand Down Expand Up @@ -3516,6 +3513,9 @@ def text(self, *args, layer=None, **kwargs):
@wraps(plt.savefig)
def savefig(self, *args, refetch_wms=False, rasterize_data=True, **kwargs):
"""Save the figure."""
# get the currently visible layer (to restore it after saving is done)
initial_layer = self.BM.bg_layer

if plt.get_backend() == "agg":
# make sure that a draw-event was triggered when using the agg backend
# (to avoid export-issues with some shapes)
Expand All @@ -3536,7 +3536,6 @@ def savefig(self, *args, refetch_wms=False, rasterize_data=True, **kwargs):
# add the figure background patch as the bottom layer
transparent = kwargs.get("transparent", False)
if transparent is False:
initial_layer = self.BM.bg_layer
showlayer_name = self.BM._get_showlayer_name(initial_layer)
layer_with_bg = "|".join(["__BG__", showlayer_name])
self.show_layer(layer_with_bg)
Expand Down Expand Up @@ -3640,25 +3639,22 @@ def savefig(self, *args, refetch_wms=False, rasterize_data=True, **kwargs):
# trigger a redraw of all savelayers to make sure unmanaged artists
# and ordinary matplotlib axes are properly drawn
self.redraw(*savelayers)
# flush events prior to savefig to avoi dissues with pending draw events
# flush events prior to savefig to avoid issues with pending draw events
# that cause wrong positioning of grid-labels and missing artists!
self.f.canvas.flush_events()
self.f._mpl_orig_savefig(*args, **kwargs)

if redraw is True:
# reset the shading-axis-size to the used figure dpi
self._update_shade_axis_size()

# restore the previous layer if background was added on save
if transparent is False:
self.show_layer(initial_layer)

# redraw after the save to ensure that backgrounds are correctly cached
self.redraw()

# restore the previous layer
elif transparent is False:
self.BM._refetch_layer("__SPINES__")
self.BM._refetch_layer("__BG__")
self.BM._refetch_layer(layer_with_bg)
self.BM.on_draw(None)
self.show_layer(initial_layer)

def fetch_layers(self, layers=None):
"""
Fetch (and cache) the layers of a map.
Expand Down Expand Up @@ -5705,5 +5701,5 @@ def cb(*args, **kwargs):
self.BM._before_fetch_bg_actions.append(cb)
self.ax._EOmaps_rounded_spine_attached = True

self.redraw("__SPINES__")
self.redraw("__SPINES__")
self.redraw("__BG__")
8 changes: 2 additions & 6 deletions eomaps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -1539,7 +1539,7 @@ def apply_layout(self, layout):
class BlitManager:
"""Manager used to schedule draw events, cache backgrounds, etc."""

_snapshot_on_update = None
_snapshot_on_update = False

def __init__(self, m):
"""
Expand Down Expand Up @@ -2727,11 +2727,7 @@ class bbox:
# don't do this! it is causing infinite loops
# cv.flush_events()

if (
blit
and not getattr(self._m, "_snapshotting", False)
and BlitManager._snapshot_on_update is True
):
if blit and BlitManager._snapshot_on_update is True:
self._m.snapshot(clear=clear_snapshot)

def blit_artists(self, artists, bg="active", blit=True):
Expand Down
8 changes: 8 additions & 0 deletions eomaps/mapsgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,3 +527,11 @@ def apply_layout(self, *args, **kwargs):
@wraps(Maps.edit_layout)
def edit_layout(self, *args, **kwargs):
return self.parent.edit_layout(*args, **kwargs)

@wraps(Maps.show)
def show(self, *args, **kwargs):
return self.parent.show(*args, **kwargs)

@wraps(Maps.snapshot)
def snapshot(self, *args, **kwargs):
return self.parent.snapshot(*args, **kwargs)
1 change: 1 addition & 0 deletions eomaps/qtcompanion/widgets/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ class ShapeSelector(QtWidgets.QFrame):
mask_radius=(float,),
flat=(str_to_bool,),
aggregator=(str,),
maxsize=(int,),
)

def __init__(self, *args, m=None, default_shape="shade_raster", **kwargs):
Expand Down

0 comments on commit a285226

Please sign in to comment.