Skip to content

Commit

Permalink
Matplotlib 3.10 Compatability
Browse files Browse the repository at this point in the history
- Fixes tricontourf not working properly
  • Loading branch information
cvanelteren authored Jan 11, 2025
1 parent 4e15fde commit 78367da
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions ultraplot/axes/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"])
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion ultraplot/tests/test_1dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
7 changes: 4 additions & 3 deletions ultraplot/tests/test_2dplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
2 changes: 2 additions & 0 deletions ultraplot/tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 78367da

Please sign in to comment.