Ternary plots as projections of Matplotlib
Project description
Mpltern (https://yuzie007.github.io/mpltern) is a Python plotting library based on Matplotlib specifically designed for ternary plots. Mpltern is implemented as a new projection for Matplotlib, with introducing e.g. new Transform classes for ternary plots. The followings are the features of mpltern when compared with other ternary-plot libraries:
Many things one expects essentially possible using Matplotlib can be done also in mpltern, without e.g. ternary-to-Cartesian conversions on the user side
For the same plotting styles, mpltern offers the same or very similar method names as Matplotlib does; you do not need to learn many new commands in addition to those for Matplotlib
Tick markers, tick labels, and axis labels are automatically positioned with reasonable paddings inherited from Matplotlib; this allows users e.g. faster production of ternary plots with publication quality
Easy combination with normal Matplotlib plots
Easy application of seaborn styles
Working also in Matplotlib interactive modes inside e.g. Jupyter notebooks
Installation
PyPI
The latest released version is available from PyPI.
python -m pip install -U mpltern
Conda
The latest released version is available from conda-forge.
conda config --add channels conda-forge
conda install mpltern
GitHub
The development version is available from GitHub.
python -m pip install -U git+https://github.com/yuzie007/mpltern.git
Basic Usage
Import mpltern as well as Matplotlib as:
import matplotlib.pyplot as plt
import mpltern
By import mpltern, a Matplotlib projection 'ternary' is registered inside.
Then, make TernaryAxes e.g. as:
ax = plt.subplot(projection='ternary')
It is already possible to create ternary plots using the methods in ax. For example:
from mpltern.ternary.datasets import get_spiral
t, l, r = mpltern.datasets.get_spiral()
# t: [0.33333333 0.33357906 0.33430414 ...]
# l: [0.33333333 0.33455407 0.33543547 ...]
# r: [0.33333333 0.33186687 0.33026039 ...]
ax.plot(t, l, r)
plt.show()
You may see the following Archimedean spiral in the triangle.
Contour-like plots are also possible in mpltern.
ax = plt.subplot(projection='ternary')
from mpltern.ternary.datasets import get_shanon_entropies
t, l, r, v = get_shanon_entropies()
# t: [ 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.1 0.1 0.1 ...]
# l: [ 0. 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1. 0. 0.1 0.2 ...]
# r: [ 1. 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0. 0.9 0.8 0.7 ...]
# v: [-0. 0.32508297 0.50040242 ...]
ax.tricontourf(t, l, r, v)
plt.show()
See more examples.
How to Cite mpltern
The author requests to cite mpltern via the DOI above if mpltern contributes to a scientific publication. Of course, Matplotlib should be also very much acknowledged when using mpltern.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.