Skip to main content

This package makes it easier for you to draw beautiful ternary diagram without pymatgen.

Project description

Ternary Diagram

python_badge license_badge Total_Downloads_badge

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

/example/contour/example_contour.png

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([[1, 1, 1], [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)

/example/example_on_readme/figure.png

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 not, 
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([[1, 1, 1], [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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ternary_diagram-2.1.0.tar.gz (12.2 kB view hashes)

Uploaded Source

Built Distribution

ternary_diagram-2.1.0-py3-none-any.whl (10.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page