Skip to content

Commit

Permalink
Merge pull request #107 from raphaelquast/dev
Browse files Browse the repository at this point in the history
Merge for v4.4.2
  • Loading branch information
raphaelquast authored Jul 26, 2022
2 parents d96a04a + 32a564d commit e5d203f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 10 deletions.
4 changes: 2 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1794,10 +1794,10 @@ Make sure to checkout the :ref:`layout_editor` which can be used to quickly re-p
| .. code-block:: python | .. image:: _static/minigifs/inset_maps.png |
| | :align: center |
| m = Maps(Maps.CRS.PlateCarree(central_longitude=-60)) | |
| m.add_feature.preset.ocean() | |
| m.add_feature.preset.ocean(reproject="cartopy") | |
| m2 = m.new_inset_map(xy=(5, 45), radius=10, | |
| plot_position=(.3, .5), plot_size=.7, | |
| edgecolor="r", linewidth=4, | |
| boundary=dict(ec="r", lw=4), | |
| indicate_extent=dict(fc=(1,0,0,.5), | |
| ec="r", lw=1) | |
| ) | |
Expand Down
6 changes: 3 additions & 3 deletions eomaps/_cb_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ def _init_cbs(self):
def _default_picker(self, artist, event):

# make sure that objects are only picked if we are on the right layer
if self._m.layer != self._m.BM.bg_layer:
if self._m.layer != "all" and self._m.layer != self._m.BM.bg_layer:
return False, None

try:
Expand Down Expand Up @@ -1051,7 +1051,7 @@ def _onpick(self, event):

# only execute onpick if the correct layer is visible
# (relevant for forwarded callbacks)
if self._m.layer != self._m.BM.bg_layer:
if self._m.layer != "all" and self._m.layer != self._m.BM.bg_layer:
return

# don't execute callbacks if a toolbar-action is active
Expand Down Expand Up @@ -1106,7 +1106,7 @@ def pickcb(event):
try:

# make sure pickcb is only executed if we are on the right layer
if self._m.layer != self._m.BM.bg_layer:
if self._m.layer != "all" and self._m.layer != self._m.BM.bg_layer:
return

# check if we want to ignore callbacks
Expand Down
2 changes: 1 addition & 1 deletion eomaps/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.4.1"
__version__ = "4.4.2"
4 changes: 2 additions & 2 deletions eomaps/_webmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def _set_style(self, style=None):
), f"EOmaps: WebMap style {style} is not available, use one of {styles}"
self._style = style[0]
else:
style = self._style
style = [self._style]

return style

Expand Down Expand Up @@ -474,7 +474,7 @@ def __call__(self, layer=None, zorder=0, alpha=1, **kwargs):
zorder=zorder,
alpha=alpha,
),
layer=layer,
layer=self._layer,
persistent=False,
m=m,
)
Expand Down
25 changes: 24 additions & 1 deletion eomaps/eomaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,7 @@ def _add_colorbar(
orientation="vertical",
log=False,
tick_formatter=None,
show_outline=False,
):

if ax_cb is None:
Expand Down Expand Up @@ -1889,7 +1890,7 @@ def _add_colorbar(
# (only if the axis has a finite size)
if ax_cb_plot.bbox.width > 0 and ax_cb_plot.bbox.height > 0:
ax_cb_plot.set_axis_on()
_ = ax_cb_plot.hist(
h = ax_cb_plot.hist(
z_data.clip(vmin, vmax) if (vmin or vmax) else z_data,
orientation=orientation,
bins=bins if (classified and histbins == "bins") else histbins,
Expand All @@ -1898,6 +1899,15 @@ def _add_colorbar(
range=(vmin, vmax) if (vmin and vmax) else None,
density=density,
)
if show_outline:
if show_outline is True:
show_outline = dict(color="k", lw=1)

if orientation == "vertical":
ax_cb_plot.step(h[1], [h[0][0], *h[0]], **show_outline)
elif orientation == "horizontal":
ax_cb_plot.step([h[0][0], *h[0]], h[1], **show_outline)

else:
ax_cb_plot.set_axis_off()

Expand Down Expand Up @@ -4079,6 +4089,7 @@ def add_colorbar(
dynamic_shade_indicator=False,
add_extend_arrows="auto",
extend_frac=0.025,
show_outline=False,
):
"""
Add a colorbar to an existing figure.
Expand Down Expand Up @@ -4187,6 +4198,17 @@ def add_colorbar(
indicate out-of-bounds values.
If None, no extension arrows will be drawn.
The default is 0.015
show_outline : bool or dict
Indicator if an outline should be added to the histogram.
(e.g. a line encompassing the histogram)
If a dict is provided, it is passed to `plt.step()` to style the line.
(e.g. with ordinary matplotlib parameters such as color, lw, ls etc.)
If True, the following properties are used:
- {"color": "k", "lw": 1}
The default is False.
See Also
--------
Expand Down Expand Up @@ -4484,6 +4506,7 @@ def redraw(*args, **kwargs):
histbins=histbins,
log=log,
tick_formatter=tick_formatter,
show_outline=show_outline,
)

# hide the colorbar if it is not added to the currently visible layer
Expand Down
30 changes: 29 additions & 1 deletion eomaps/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ def cb_move_with_key(self, event):
max(0.25, snapy),
)

b = [0, 0, 0, 0]
for ax in self._ax_picked:
if key == "left":
bbox = Bbox.from_bounds(
Expand Down Expand Up @@ -346,7 +347,34 @@ def cb_move_with_key(self, event):

bbox = bbox.transformed(self.f.transFigure.inverted())

ax.set_position(bbox)
# ax.set_position(bbox)
if not self._cb_picked:
ax.set_position(bbox)
else:
orientation = self._m_picked._colorbar[-2]
if orientation == "horizontal":
b = [
bbox.x0,
min(b[1], bbox.y0) if b[1] > 0 else bbox.y0,
bbox.width,
b[3] + bbox.height,
]

elif orientation == "vertical":
b = [
min(b[0], bbox.x0) if b[0] > 0 else bbox.x0,
bbox.y0,
b[2] + bbox.width,
bbox.height,
]

if (
self._cb_picked
and (self._m_picked is not None)
and (self._ax_picked is not None)
and not all((i == 0 for i in b))
):
self._m_picked.figure.set_colorbar_position(b)

self.set_annotations()
self._color_axes()
Expand Down
10 changes: 10 additions & 0 deletions eomaps/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ def GeoTIFF(
elif isinstance(path_or_dataset, xar.Dataset):
# if an xar.Dataset is provided, use it
ncfile = path_or_dataset
else:
raise ValueError(
"EOmaps: `m.read_file.GeoTIFF` accepts only a path "
+ "to a GeoTIFF file or an `xarray.Dataset` object!"
)

if sel is not None:
usencfile = ncfile.sel(**sel)
Expand Down Expand Up @@ -348,6 +353,11 @@ def NetCDF(
elif isinstance(path_or_dataset, xar.Dataset):
# if an xar.Dataset is provided, use it
ncfile = path_or_dataset
else:
raise ValueError(
"EOmaps: `m.read_file.NetCDF` accepts only a path "
+ "to a NetCDF file or an `xarray.Dataset` object!"
)

if sel is not None:
usencfile = ncfile.sel(**sel)
Expand Down

0 comments on commit e5d203f

Please sign in to comment.