Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions docs/examples/plot_types/08_ternary.py
Original file line number Diff line number Diff line change
@@ -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 <ug_external_axes>`
"""

# %%
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()
2 changes: 2 additions & 0 deletions docs/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
------------------------------------------

Expand Down
28 changes: 28 additions & 0 deletions ultraplot/axes/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading