Skip to content

Commit 1c9e4bb

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/v1.72.0
2 parents a48a58a + 4b452da commit 1c9e4bb

3 files changed

Lines changed: 70 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Ternary Plots
3+
=============
4+
Ternary plots are a type of plot that displays the proportions of three variables that sum to a constant. They are commonly used in fields such as geology, chemistry, and materials science to represent the composition of mixtures. UltraPlot makes it easy to create publication-quality ternary plots using the `mpltern` library as a backend.
5+
6+
Why UltraPlot here?
7+
-------------------
8+
UltraPlot offers seamless integration with `mpltern`, allowing users to create and customize ternary plots with minimal effort. UltraPlot's high-level API simplifies the process of setting up ternary plots, adding data, and formatting the axes and labels.
9+
10+
See also
11+
--------
12+
* :ref:`External axes containers <ug_external_axes>`
13+
"""
14+
15+
# %%
16+
import mpltern
17+
18+
19+
from mpltern.datasets import get_shanon_entropies, get_spiral
20+
import ultraplot as uplt, numpy as np
21+
22+
t, l, r, v = get_shanon_entropies()
23+
24+
fig, ax = uplt.subplots(projection="ternary")
25+
vmin = 0.0
26+
vmax = 1.0
27+
levels = np.linspace(vmin, vmax, 7)
28+
29+
cs = ax.tripcolor(t, l, r, v, cmap="lapaz_r", shading="flat", vmin=vmin, vmax=vmax)
30+
ax.set_title("Ternary Plot of Shannon Entropies")
31+
ax.plot(*get_spiral(), color="white", lw=1.25)
32+
colorbar = ax.colorbar(
33+
cs,
34+
loc="b",
35+
align="c",
36+
title="Entropy",
37+
length=0.33,
38+
)
39+
40+
fig.show()

docs/usage.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ plotting packages.
158158
Since these features are optional,
159159
UltraPlot can be used without installing any of these packages.
160160

161+
.. _ug_external_axes:
162+
161163
External axes containers (mpltern, others)
162164
------------------------------------------
163165

ultraplot/axes/container.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,34 @@ def pcolormesh(self, *args, **kwargs):
610610
return self._external_axes.pcolormesh(*args, **kwargs)
611611
return super().pcolormesh(*args, **kwargs)
612612

613+
def tripcolor(self, *args, **kwargs):
614+
"""Delegate tripcolor to external axes."""
615+
if self._external_axes is not None:
616+
self._external_stale = True # Mark for redraw
617+
return self._external_axes.tripcolor(*args, **kwargs)
618+
return super().tripcolor(*args, **kwargs)
619+
620+
def tricontour(self, *args, **kwargs):
621+
"""Delegate tricontour to external axes."""
622+
if self._external_axes is not None:
623+
self._external_stale = True # Mark for redraw
624+
return self._external_axes.tricontour(*args, **kwargs)
625+
return super().tricontour(*args, **kwargs)
626+
627+
def tricontourf(self, *args, **kwargs):
628+
"""Delegate tricontourf to external axes."""
629+
if self._external_axes is not None:
630+
self._external_stale = True # Mark for redraw
631+
return self._external_axes.tricontourf(*args, **kwargs)
632+
return super().tricontourf(*args, **kwargs)
633+
634+
def triplot(self, *args, **kwargs):
635+
"""Delegate triplot to external axes."""
636+
if self._external_axes is not None:
637+
self._external_stale = True # Mark for redraw
638+
return self._external_axes.triplot(*args, **kwargs)
639+
return super().triplot(*args, **kwargs)
640+
613641
def imshow(self, *args, **kwargs):
614642
"""Delegate imshow to external axes."""
615643
if self._external_axes is not None:

0 commit comments

Comments
 (0)