Skip to content

Commit 9988e62

Browse files
committed
test warning no labels found
1 parent 2067fc0 commit 9988e62

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

mplotutils/_cartopy_utils.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,8 @@ def ylabel_map(s, *, labelpad=None, size=None, weight=None, y=0.5, ax=None, **kw
168168
if ax is None:
169169
ax = plt.gca()
170170

171+
ax.set_ylabel
172+
171173
labelpad, size, weight = _get_label_attr(labelpad, size, weight)
172174

173175
va = kwargs.pop("va", "bottom")
@@ -322,10 +324,10 @@ def yticklabels(
322324

323325
if not y_label_points:
324326
msg = (
325-
"WARN: no points found for ylabel\n"
327+
"no points found for ylabel\n"
326328
f"y_lim is: {y_lim[0]:0.2f} to {y_lim[1]:0.2f}"
327329
)
328-
warnings.warn(msg)
330+
warnings.warn(msg, stacklevel=2)
329331

330332
# get a transform instance that mpl understands
331333
transform = ccrs.PlateCarree()._as_mpl_transform(ax)
@@ -421,10 +423,10 @@ def xticklabels(
421423

422424
if not x_label_points:
423425
msg = (
424-
"WARN: no points found for xlabel\n"
426+
"no points found for xlabel with"
425427
f"x_lim is: {x_lim[0]:0.2f} to {x_lim[1]:0.2f}"
426428
)
427-
warnings.warn(msg)
429+
warnings.warn(msg, stacklevel=2)
428430

429431
# get a transform instance that mpl understands
430432
transform = ccrs.PlateCarree()._as_mpl_transform(ax)

mplotutils/tests/test_mapticklabels.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def test_xticklabels_robinson(pass_ax):
7171
assert ax.texts[-1].get_text() == "120°E"
7272

7373

74+
def test_xyticklabels_not_on_map():
75+
76+
with subplots_context(subplot_kw=dict(projection=ccrs.PlateCarree())) as (f, ax):
77+
# restrict extent
78+
ax.set_extent([0, 180, -90, 0], ccrs.PlateCarree())
79+
80+
with pytest.warns(match="no points found for xlabel"):
81+
mpu.xticklabels([180, 270, 360], ax=ax, size=8)
82+
83+
with pytest.warns(match="no points found for ylabel"):
84+
mpu.yticklabels([0, 45, 90], ax=ax, size=8)
85+
86+
7487
# TODO: https://github.com/mpytools/mplotutils/issues/48
7588
# def test_xticklabels_robinson_180():
7689

0 commit comments

Comments
 (0)