diff --git a/ultraplot/axes/plot.py b/ultraplot/axes/plot.py index 78531dcc..17da6e2e 100644 --- a/ultraplot/axes/plot.py +++ b/ultraplot/axes/plot.py @@ -1467,8 +1467,7 @@ def _add_contour_labels( on unfilled contour object (otherwise errors crop up). """ # Parse input args - zorder = max((h.get_zorder() for h in obj.collections), default=3) - zorder = max(3, zorder + 1) + zorder = max(3, obj.get_zorder() + 1) kwargs.setdefault("zorder", zorder) colors = _not_none(c=c, color=color, colors=colors) fontsize = _not_none(size=size, fontsize=fontsize, default=rc["font.smallsize"]) @@ -1808,10 +1807,11 @@ def _fix_patch_edges(obj, edgefix=None, **kwargs): obj.set_linewidth(linewidth) obj.set_edgecolor("face") - for contour in obj.collections: - contour.set_linestyle("-") - contour.set_linewidth(linewidth) - contour.set_edgecolor("face") + import matplotlib.patheffects as pe + + obj.set_path_effects( + [pe.Stroke(linewidth=linewidth, linestyle="-", foreground="face")] + ) elif isinstance(obj, mcollections.Collection): # e.g. QuadMesh, PolyCollection obj.set_linewidth(linewidth) obj.set_edgecolor("face") diff --git a/ultraplot/tests/test_1dplots.py b/ultraplot/tests/test_1dplots.py index 6eb0ef40..60eed6d0 100644 --- a/ultraplot/tests/test_1dplots.py +++ b/ultraplot/tests/test_1dplots.py @@ -412,7 +412,7 @@ def test_triplot_variants(x, y, z, triangles, use_triangulation, use_datadict): ax.tricontourf(triangulation, z, levels=64, cmap="PuBu") elif use_datadict: ax.tricontourf("x", "y", "z", data=df) - return + return fig else: # Use direct x, y, z inputs ax.tricontourf(x, y, z, triangles=triangles, levels=64, cmap="PuBu") diff --git a/ultraplot/tests/test_2dplots.py b/ultraplot/tests/test_2dplots.py index 5ae805a4..823484d2 100644 --- a/ultraplot/tests/test_2dplots.py +++ b/ultraplot/tests/test_2dplots.py @@ -123,9 +123,10 @@ def test_contour_labels(): ax = axs[1] m = ax.contourf(data) ax.clabel(m, colors="black", fontsize="large") # looks fine without this - for o in m.collections: - o.set_linewidth(1.5) - o.set_edgecolor("k") + + import matplotlib.patheffects as pe + + m.set_path_effects([pe.Stroke(linewidth=1.5, foreground="k"), pe.Normal()]) return fig diff --git a/ultraplot/tests/test_format.py b/ultraplot/tests/test_format.py index dad3171f..9d8be905 100644 --- a/ultraplot/tests/test_format.py +++ b/ultraplot/tests/test_format.py @@ -28,6 +28,8 @@ def test_ignored_keywords(): subplot_kw={"proj": "cart"}, subplotpars={"left": 0.2}, ) + # only capture ultraplot warnings not general mpl warnings, e.g. deprecation warnings + record = [r for r in record if "UltraPlotWarning" in str(r)] assert len(record) == 3 with warnings.catch_warnings(record=True) as record: fig.subplots_adjust(left=0.2)