ternary_diagram package
- class ternary_diagram.TernaryDiagram(materials: Tuple[str, str, str], ax: Axes | None = None, auto_latex_notation: bool = True)
Bases:
object
- annotate(text: str, vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], **kwargs) Annotation
Annotate text.
This is a wrapper of matplotlib.pyplot.annotate.
- Parameters:
text (str) – Text to be displayed.
vector (1D ArrayLike, whose length is 3.) –
vector : ArrayLike | shape = (3,) It represents the ratio of each component (the sum does not have to be 1).
The vectors are specified in semi-clockwise order starting from the vertex of the triangle.
kwargs (parameter of matplotlib.pyplot.annotate, optional) – See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.annotate.html
- Returns:
An annotation.
- Return type:
matplotlib.text.Annotation
- property ax: Axes
Axes object
- colorbar(mappable, shrink: float = 0.8, format='%.1f', label: str = '', orientation: str = 'vertical', location: str = 'right', **kwargs) Colorbar
Draw a colorbar.
This is a wrapper of matplotlib.pyplot.colorbar.
See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.colorbar.html
- Parameters:
mappable (matplotlib.cm.ScalarMappable) – The object that contains the colorbar data.
shrink (float, optional) – how much to shrink the colorbar, by default 0.8
format (str, optional) – float format, by default ‘%.1f’
label (str, optional) – bar label, by default ‘’
orientation (str, optional) – bar orientation, by default ‘vertical’
location (str, optional) – location, by default ‘right’
kwargs (parameter of matplotlib.pyplot.colorbar, optional) – See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.colorbar.html
- Returns:
colorbar object
- Return type:
matplotlib.colorbar.Colorbar
- contour(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], z: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, z_min: Number | None = None, z_max: Number | None = None, fill: bool = True, flag_cbar: bool = True, **kwargs) TriContourSet
To create a contour map.
This is a wrapper of plt.tricontour or plt.tricontourf.
See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontour.html or https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.tricontourf.html
When fill is True, this is a wrapper of plt.tricontourf.
When fill is False, this is a wrapper of plt.tricontour.
- Parameters:
vector (ArrayLike | shape = (n, 3)) –
2D vector whose shape is (n, 3). It represents the ratio of each component (the sum does not have to be 1).
The vectors are specified in semi-clockwise order starting from the vertex of the triangle.
z (Optional[ArrayLike], shape = (n,)) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
kwargs (parameter of matplotlib.pyplot.contour, optional) – See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.contour.html.
- Returns:
A collection of contour lines.
- Return type:
matplotlib.tri.tricontour.TriContourSet
- property fig: Figure
Figure object
- plot(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], **kwargs) List[Line2D]
To draw a tie line.
This is a wrapper of matplotlib.pyplot.plot.
- Parameters:
vector (ArrayLike | shape = (n, 3)) –
vector : ArrayLike | shape = (n, 3) 2D vector whose shape is (n, 3). It represents the ratio of each component (the sum does not have to be 1).
The vectors are specified in semi-clockwise order starting from the vertex of the triangle.
kwargs (parameter of matplotlib.pyplot.plot, optional) – See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.plot.html
- Returns:
lines.
- Return type:
List[matplotlib.lines.Line2D]
- scatter(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], z: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, z_min: Number | None = None, z_max: Number | None = None, annotations: List[str] | None = None, flag_cbar: bool = True, **kwargs) PathCollection
Plot scatter points.
This is a wrapper of matplotlib.pyplot.scatter.
- Parameters:
vector (ArrayLike | shape = (n, 3)) –
vector : ArrayLike | shape = (n, 3) 2D vector whose shape is (n, 3). It represents the ratio of each component (the sum does not have to be 1).
The vectors are specified in semi-clockwise order starting from the vertex of the triangle.
z (ArrayLike, shape = (n,), optional) – , by default None
z_min (Optional[Number] , optional) – , by default None
z_max (Optional[Number], optional) – , by default None
annotations (Optional[List[str]], optional) – instance annotations, by default None if None, nothing is annotated.
flag_cbar (bool, optional) – instance colorbar or not, by default True
kwargs (parameter of matplotlib.pyplot.scatter, optional) –
For example, marker=’x’, facecolor=’blue’ etc.
See https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.scatter.html.
- Returns:
A collection of scatter points.
- Return type:
matplotlib.collections.PathCollection
Submodules
ternary_diagram.utils module
- ternary_diagram.utils.check_1d_vector(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], scale: bool = True) ndarray
check 1d vector
- Parameters:
vector (ArrayLike | shape = (3,)) – ratio
scale (bool, optional) – minmaxscale or not, by default True
Examples
>>> check_1d_vector([1, 2, 3], scale=False) array([[1, 2, 3]])
>>> check_1d_vector([2, 2, 4], scale=True) array([[0.25, 0.25, 0.5 ]])
- Return type:
np.ndarray | shape = (1, 3)
- ternary_diagram.utils.check_2d_vector(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], scale: bool = True) ndarray
check 2d vector
- Parameters:
vector (ArrayLike | shape = (n, 3)) – ratio
scale (bool, optional) – minmaxscale or not, by default True
- Return type:
numpy.ndarray | shape = (n, 3)
- Raises:
ValueError – when shape is not (n, 3)
- ternary_diagram.utils.check_ax(ax: Axes | None) Axes
check ax
- Parameters:
ax (None or Axes object) – if None, get current axes
- Return type:
Axes object
- Raises:
TypeError – when ax is not None or Axes object
- ternary_diagram.utils.get_label(compound_name: str) str
Convert the chemical composition to LaTeX notation.
- Parameters:
compound_name (str) – A compound name, like ‘Li2O’
- Returns:
Chemical composition converted to LaTeX notation.
- Return type:
str
Examples
>>> get_label('Li2O') 'Li$_{2}$O'
>>> get_label('(LiLa)0.5TiO3') '(LiLa)$_{0.5}$TiO$_{3}$'
- Raises:
ValueError – when compound_name is not str.
- ternary_diagram.utils.three2two(vector: Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes]) Tuple[ndarray, ndarray]
Converted 3D proportions to 2D in order to generate a triangular diagram.
- Parameters:
vector (ArrayLike | shape = (n, 3)) – ratio
Examples
>>> three2two(check_2d_vector([[2, 2, 4]])) (array([0.625]), array([0.21650635]))
- Return type:
numpy.ndarray | shape = (n, 2)