This package makes it easier for you to draw beautiful ternary diagram without pymatgen.
Project description
Ternary Diagram
This package makes it easier for you to draw beautiful ternary diagram without pymatgen.
Meaningly, only need numpy
, pandas
and matplotlib
.
What you will be able to do with this package
- Create beautiful contour maps easily
- Creating a scatter plot
- Draw tie lines
- Automatically format chemical composition using subscripts
- Most of the matplotlib options are available
First of all
This package works well with the element_recognition package (my own package) because it has a function (get_ratio
) that converts composition to ratio.
For example,
from element_recognition import get_ratio
get_ratio(products = ['LiLa2TiO6'], materials = ['Li2O', 'La2O3', 'TiO2'])
Li2O La2O3 TiO2
Li2La2TiO6 1.0 1.0 1.0
How to install
pip install ternary-diagram
PyPI project is here.
Usage
See Examples and the documentation.
Examples
An easy example is here.
import matplotlib.pyplot as plt
from ternary_diagram import TernaryDiagram
td = TernaryDiagram(['Li2O', 'La2O3', 'TiO2'])
td.scatter(vector = [[1, 1, 1], [1, 2, 3]], z = [0, 1])
td.scatter(vector = [[2, 1, 3], [3, 2, 1]], marker = 's', c = '#022c5e', s = 30) # You can set some options in matplotlib.pyplot.scatter like `marker`, `c` etc.
td.plot(r1 = [1, 1, 1], r2 = [1, 2, 3], color = 'black') # You can set some options in matplotlib.pyplot.plot like `lw`, `c`, and so on.
plt.savefig('figure.png', dpi = 144)
It can be written like this.
import matplotlib.pyplot as plt
from ternary_diagram import TernaryDiagram
fig, ax = plt.subplots(facecolor='w') # The background color is sometimes transparent in jupyter notebooks, so set facecolor 'white'.
td = TernaryDiagram(['Li2O', 'La2O3', 'TiO2'], ax=ax) # You can set `ax` to select which axes to draw. If None, automatically select or generate.
td.scatter(vector = [[1, 1, 1], [1, 2, 3]], z = [0, 1])
td.scatter(vector = [[2, 1, 3], [3, 2, 1]], marker = 's', c = '#022c5e', s = 30) # You can set some options in matplotlib.pyplot.scatter like `marker`, `c` etc.
td.plot(r1 = [1, 1, 1], r2 = [1, 2, 3], color = 'black') # You can set some options in matplotlib.pyplot.plot like `lw`, `c`, and so on.
fig.savefig('figure.png', dpi = 144)
It means that you can draw multiple figures in one figure object.
See also the example folder. In particular, if you want to know how to use element_recognition as well, please refer to example/scatter/example _scatter_with_annotations.ipynb.
LICENSE
See LICENSE.
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.
Source Distribution
Built Distribution
Hashes for ternary_diagram-2.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbfe584596e533acb8ab76ca09087882df04f33afaacb43b92babc39e4e46a3c |
|
MD5 | 2fc35ab68b8dd667ca62ae1007c8037d |
|
BLAKE2b-256 | 17f2be4c81edbde3338e95e7cb03a9cbd00083e3e2aa056fa238fa54fbfeaf02 |