From fef744eeff2a163d20baafeb4de1e3d2bba5066b Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 4 Jun 2026 13:27:41 +1000 Subject: [PATCH 1/2] add gepcel example --- .../legend_types/01_semantic_legends.py | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 docs/examples/legend_types/01_semantic_legends.py diff --git a/docs/examples/legend_types/01_semantic_legends.py b/docs/examples/legend_types/01_semantic_legends.py new file mode 100644 index 000000000..607be0709 --- /dev/null +++ b/docs/examples/legend_types/01_semantic_legends.py @@ -0,0 +1,101 @@ +""" +Semantic legends +================ +With UltraPlot semantic legends can be expressed in a flexible and cohesive manner with customg glyphs, latex and or spatial locations. +""" + +# Semantic Legend with custom markers and advanced styles +import matplotlib.transforms as mtransforms +import numpy as np +from matplotlib.markers import CapStyle, JoinStyle, MarkerStyle +from matplotlib.path import Path + +import ultraplot as uplt + +star = Path.unit_regular_star(6) +circle = Path.unit_circle() +star_path = Path.unit_regular_star(5) +cut_star = Path( + vertices=np.concatenate([circle.vertices, star.vertices[::-1, ...]]), + codes=np.concatenate([circle.codes, star.codes]), +) + +fig, ax = uplt.subplots() + +# upper left legend with custom mark +ax.catlegend( + ["star", "cus_star"], + marker=[star_path, cut_star], + markersize=10, + add=True, + loc="ul", + title="Paths", + ncols=1, +) + +# upper right legend with advanced CapStyle and JoinStyle +ax.catlegend( + ["butt / round", "round / miter", "projecting / bevel"], + marker="1", + markersize=10, + markeredgecolor=list("gbr"), + markeredgewidth=4, + markerfacecoloralt="none", + marker_capstyle=[ + CapStyle.butt, + CapStyle.round, + CapStyle.projecting, + ], + marker_joinstyle=[ + JoinStyle.round, + JoinStyle.miter, + JoinStyle.bevel, + ], + marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [0, 30, 60]], + title="Cap & Join Style", + add=True, + loc="ur", + ncols=1, +) + +# center geolegend with different styles +ax.geolegend( + ["rect", "tri", "hex", "AU"], + facecolor=["tab:red", "r", "k", "tab:blue"], + ec=["k", "g", "orange", "bright pink"], + loc="c", + title="geolegend", + ew=[0.5, 2, 1, 0.5], + markersize=10, + ncols=4, + handletextpad=0.1, + columnspacing=0.7, +) + +# lower left legend with TeX symbols and rotation transform +ax.catlegend( + ["\\infty", "\\sum", "\\int"], + marker=[r"$\infty$", r"$\sum$", r"$\int$"], + s=[6, 18, 9], # ms/markersize=[6,8,10] + title="TeX symbols\nwith rotation", + marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [30, 90, 45]], + add=True, + loc="ll", + ncols=1, +) + +# lower right legend with different fill style +ax.catlegend( + ["top", "bottom", "left", "right"], + marker="o", + markersize=10, + mfc=["r", "g", "b", "c"], + markerfacecoloralt="lightsteelblue", + markeredgecolor=["k", "r", "y", "b"], + fillstyle=["top", "bottom", "left", "right"], + title="Half filled", + add=True, + loc="lr", + ncols=1, +) +ax.axis("off") From eb394b8c9b864badfd66929e09c69e0ad421f568 Mon Sep 17 00:00:00 2001 From: cvanelteren Date: Thu, 4 Jun 2026 13:55:55 +1000 Subject: [PATCH 2/2] merge with existing --- .../legend_types/01_semantic_legends.py | 96 ------------------ .../legends_colorbars/03_semantic_legends.py | 98 +++++++++++++++++++ 2 files changed, 98 insertions(+), 96 deletions(-) diff --git a/docs/examples/legend_types/01_semantic_legends.py b/docs/examples/legend_types/01_semantic_legends.py index 607be0709..470bbe93b 100644 --- a/docs/examples/legend_types/01_semantic_legends.py +++ b/docs/examples/legend_types/01_semantic_legends.py @@ -3,99 +3,3 @@ ================ With UltraPlot semantic legends can be expressed in a flexible and cohesive manner with customg glyphs, latex and or spatial locations. """ - -# Semantic Legend with custom markers and advanced styles -import matplotlib.transforms as mtransforms -import numpy as np -from matplotlib.markers import CapStyle, JoinStyle, MarkerStyle -from matplotlib.path import Path - -import ultraplot as uplt - -star = Path.unit_regular_star(6) -circle = Path.unit_circle() -star_path = Path.unit_regular_star(5) -cut_star = Path( - vertices=np.concatenate([circle.vertices, star.vertices[::-1, ...]]), - codes=np.concatenate([circle.codes, star.codes]), -) - -fig, ax = uplt.subplots() - -# upper left legend with custom mark -ax.catlegend( - ["star", "cus_star"], - marker=[star_path, cut_star], - markersize=10, - add=True, - loc="ul", - title="Paths", - ncols=1, -) - -# upper right legend with advanced CapStyle and JoinStyle -ax.catlegend( - ["butt / round", "round / miter", "projecting / bevel"], - marker="1", - markersize=10, - markeredgecolor=list("gbr"), - markeredgewidth=4, - markerfacecoloralt="none", - marker_capstyle=[ - CapStyle.butt, - CapStyle.round, - CapStyle.projecting, - ], - marker_joinstyle=[ - JoinStyle.round, - JoinStyle.miter, - JoinStyle.bevel, - ], - marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [0, 30, 60]], - title="Cap & Join Style", - add=True, - loc="ur", - ncols=1, -) - -# center geolegend with different styles -ax.geolegend( - ["rect", "tri", "hex", "AU"], - facecolor=["tab:red", "r", "k", "tab:blue"], - ec=["k", "g", "orange", "bright pink"], - loc="c", - title="geolegend", - ew=[0.5, 2, 1, 0.5], - markersize=10, - ncols=4, - handletextpad=0.1, - columnspacing=0.7, -) - -# lower left legend with TeX symbols and rotation transform -ax.catlegend( - ["\\infty", "\\sum", "\\int"], - marker=[r"$\infty$", r"$\sum$", r"$\int$"], - s=[6, 18, 9], # ms/markersize=[6,8,10] - title="TeX symbols\nwith rotation", - marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [30, 90, 45]], - add=True, - loc="ll", - ncols=1, -) - -# lower right legend with different fill style -ax.catlegend( - ["top", "bottom", "left", "right"], - marker="o", - markersize=10, - mfc=["r", "g", "b", "c"], - markerfacecoloralt="lightsteelblue", - markeredgecolor=["k", "r", "y", "b"], - fillstyle=["top", "bottom", "left", "right"], - title="Half filled", - add=True, - loc="lr", - ncols=1, -) -ax.axis("off") diff --git a/docs/examples/legends_colorbars/03_semantic_legends.py b/docs/examples/legends_colorbars/03_semantic_legends.py index ea58d5bb9..3ae0948f6 100644 --- a/docs/examples/legends_colorbars/03_semantic_legends.py +++ b/docs/examples/legends_colorbars/03_semantic_legends.py @@ -18,6 +18,104 @@ * :doc:`Colorbars and legends ` """ +# %% +# Semantic Legend with custom markers and advanced styles +import matplotlib.transforms as mtransforms +import numpy as np +from matplotlib.markers import CapStyle, JoinStyle, MarkerStyle +from matplotlib.path import Path + +import ultraplot as uplt + +star = Path.unit_regular_star(6) +circle = Path.unit_circle() +star_path = Path.unit_regular_star(5) +cut_star = Path( + vertices=np.concatenate([circle.vertices, star.vertices[::-1, ...]]), + codes=np.concatenate([circle.codes, star.codes]), +) + +fig, ax = uplt.subplots() + +# upper left legend with custom mark +ax.catlegend( + ["star", "cus_star"], + marker=[star_path, cut_star], + markersize=10, + add=True, + loc="ul", + title="Paths", + ncols=1, +) + +# upper right legend with advanced CapStyle and JoinStyle +ax.catlegend( + ["butt / round", "round / miter", "projecting / bevel"], + marker="1", + markersize=10, + markeredgecolor=list("gbr"), + markeredgewidth=4, + markerfacecoloralt="none", + marker_capstyle=[ + CapStyle.butt, + CapStyle.round, + CapStyle.projecting, + ], + marker_joinstyle=[ + JoinStyle.round, + JoinStyle.miter, + JoinStyle.bevel, + ], + marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [0, 30, 60]], + title="Cap & Join Style", + add=True, + loc="ur", + ncols=1, +) + +# center geolegend with different styles +ax.geolegend( + ["rect", "tri", "hex", "AU"], + facecolor=["tab:red", "r", "k", "tab:blue"], + ec=["k", "g", "orange", "bright pink"], + loc="c", + title="geolegend", + ew=[0.5, 2, 1, 0.5], + markersize=10, + ncols=4, + handletextpad=0.1, + columnspacing=0.7, +) + +# lower left legend with TeX symbols and rotation transform +ax.catlegend( + ["\\infty", "\\sum", "\\int"], + marker=[r"$\infty$", r"$\sum$", r"$\int$"], + s=[6, 18, 9], # ms/markersize=[6,8,10] + title="TeX symbols\nwith rotation", + marker_transform=[mtransforms.Affine2D().rotate_deg(x) for x in [30, 90, 45]], + add=True, + loc="ll", + ncols=1, +) + +# lower right legend with different fill style +ax.catlegend( + ["top", "bottom", "left", "right"], + marker="o", + markersize=10, + mfc=["r", "g", "b", "c"], + markerfacecoloralt="lightsteelblue", + markeredgecolor=["k", "r", "y", "b"], + fillstyle=["top", "bottom", "left", "right"], + title="Half filled", + add=True, + loc="lr", + ncols=1, +) +ax.axis("off") + + # %% import cartopy.crs as ccrs import shapely.geometry as sg