diff --git a/docs/examples/plot_types/08_ternary.py b/docs/examples/plot_types/08_ternary.py new file mode 100644 index 000000000..f84eb3384 --- /dev/null +++ b/docs/examples/plot_types/08_ternary.py @@ -0,0 +1,40 @@ +""" +Ternary Plots +============= +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. + +Why UltraPlot here? +------------------- +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. + +See also +-------- +* :ref:`External axes containers ` +""" + +# %% +import mpltern + + +from mpltern.datasets import get_shanon_entropies, get_spiral +import ultraplot as uplt, numpy as np + +t, l, r, v = get_shanon_entropies() + +fig, ax = uplt.subplots(projection="ternary") +vmin = 0.0 +vmax = 1.0 +levels = np.linspace(vmin, vmax, 7) + +cs = ax.tripcolor(t, l, r, v, cmap="lapaz_r", shading="flat", vmin=vmin, vmax=vmax) +ax.set_title("Ternary Plot of Shannon Entropies") +ax.plot(*get_spiral(), color="white", lw=1.25) +colorbar = ax.colorbar( + cs, + loc="b", + align="c", + title="Entropy", + length=0.33, +) + +fig.show() diff --git a/docs/usage.rst b/docs/usage.rst index 7ca540138..f70d90a6f 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -158,6 +158,8 @@ plotting packages. Since these features are optional, UltraPlot can be used without installing any of these packages. +.. _ug_external_axes: + External axes containers (mpltern, others) ------------------------------------------ diff --git a/ultraplot/axes/container.py b/ultraplot/axes/container.py index 2afd07f4d..56f1dbcb8 100644 --- a/ultraplot/axes/container.py +++ b/ultraplot/axes/container.py @@ -610,6 +610,34 @@ def pcolormesh(self, *args, **kwargs): return self._external_axes.pcolormesh(*args, **kwargs) return super().pcolormesh(*args, **kwargs) + def tripcolor(self, *args, **kwargs): + """Delegate tripcolor to external axes.""" + if self._external_axes is not None: + self._external_stale = True # Mark for redraw + return self._external_axes.tripcolor(*args, **kwargs) + return super().tripcolor(*args, **kwargs) + + def tricontour(self, *args, **kwargs): + """Delegate tricontour to external axes.""" + if self._external_axes is not None: + self._external_stale = True # Mark for redraw + return self._external_axes.tricontour(*args, **kwargs) + return super().tricontour(*args, **kwargs) + + def tricontourf(self, *args, **kwargs): + """Delegate tricontourf to external axes.""" + if self._external_axes is not None: + self._external_stale = True # Mark for redraw + return self._external_axes.tricontourf(*args, **kwargs) + return super().tricontourf(*args, **kwargs) + + def triplot(self, *args, **kwargs): + """Delegate triplot to external axes.""" + if self._external_axes is not None: + self._external_stale = True # Mark for redraw + return self._external_axes.triplot(*args, **kwargs) + return super().triplot(*args, **kwargs) + def imshow(self, *args, **kwargs): """Delegate imshow to external axes.""" if self._external_axes is not None: