ternary_diagram.ternary_diagram module
Copyright © 2021 yu9824
- class ternary_diagram.ternary_diagram.TernaryDiagram(materials: Tuple[str, str, str], ax: Optional[matplotlib.axes._axes.Axes] = None, auto_latex_notation: bool = True)
Bases:
object
Make instance.
Create borders, etc. for triangulation diagrams.
- Parameters
materials (Tuple[str, str, str]) –
A one-dimensional list of compounds that constitute an endpoint when generating a ternary_diagram.
Specify counterclockwise from the top vertex of the triangle.
ax (Optional[matplotlib.axes.Axes], optional) – Axes object to draw a diagram. If None, automatically generate.
auto_latex_notation (bool, optional) – If True, the LaTeX notation of the material is automatically generated. If False, the material is displayed as it is.
Examples
>>> from ternary_diagram import TernaryDiagram
>>> # You can set `ax` to select which axes to draw. >>> # If not, the current axes will be used. >>> td = TernaryDiagram(["Li2O", "La2O3", "TiO2"])
>>> # scatter >>> td.scatter(vector=[[1, 1, 1], [1, 2, 3]], z=[0, 1]) >>> # You can set some options in `plt.scatter` like `marker`, `c` etc. >>> td.scatter([[2, 1, 3], [3, 2, 1]], marker="s", c="#022c5e", s=30)
>>> # line plot >>> # You can set some options in `plt.plot` like `lw`, `c`, and so on. >>> td.plot([[1, 1, 1], [1, 2, 3]], color="black")
>>> # save figure >>> td.fig.savefig("figure.png", dpi=144)
- _append_x_y(plotter) None
append x, y data
- Parameters
plotter (_BasePlotter) – plotter
- Raises
TypeError – “plotter must inherit _BasePlotter”
- annotate(text: str, vector: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], **kwargs) matplotlib.text.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: matplotlib.axes._axes.Axes
Axes object
- colorbar(mappable, shrink: float = 0.8, format='%.1f', label: str = '', orientation: str = 'vertical', location: str = 'right', **kwargs) matplotlib.colorbar.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: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], z: Optional[Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, z_min: Optional[numbers.Number] = None, z_max: Optional[numbers.Number] = None, fill: bool = True, flag_cbar: bool = True, **kwargs) matplotlib.tri.tricontour.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: matplotlib.figure.Figure
Figure object
- plot(vector: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], **kwargs) List[matplotlib.lines.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: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], z: Optional[Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, z_min: Optional[numbers.Number] = None, z_max: Optional[numbers.Number] = None, annotations: Optional[List[str]] = None, flag_cbar: bool = True, **kwargs) matplotlib.collections.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
- class ternary_diagram.ternary_diagram._AnnotatePlotter(text, vector, ax=None, **kwargs)
Bases:
ternary_diagram.ternary_diagram._BasePlotter
This is a base class for the wrapper of matplotlib.pyplot. functions.
- Parameters
vector (ArrayLike) – vector
ax (Optional[matplotlib.axes.Axes], optional) – , by default None
z (Optional[ArrayLike], optional) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
- property name
Plotter name
- class ternary_diagram.ternary_diagram._BasePlotter(vector: Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]], ax: Optional[matplotlib.axes._axes.Axes] = None, z: Optional[Union[numpy.typing._array_like._SupportsArray[numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[Union[bool, int, float, complex, str, bytes]]]] = None, z_min: Optional[numbers.Number] = None, z_max: Optional[numbers.Number] = None, **kwargs)
Bases:
object
This is a base class for the wrapper of matplotlib.pyplot. functions.
- Parameters
vector (ArrayLike) – vector
ax (Optional[matplotlib.axes.Axes], optional) – , by default None
z (Optional[ArrayLike], optional) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
- _set_default_params(**kwargs)
set default params
Examples
>>> self._set_default_params(zorder=2)
- property collection_
- static colorbar(mappable: Optional[Union[matplotlib.cm.ScalarMappable, Any]] = None, shrink: float = 0.8, format='%.1f', label: str = '', orientation: str = 'vertical', location: str = 'right', ax: Optional[matplotlib.axes._axes.Axes] = None, **kwargs) matplotlib.colorbar.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 (Optional[Union[matplotlib.cm.ScalarMappable, Any]]) – 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’
ax (Optional[matplotlib.axes.Axes], optional) – axes object, by default None
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
- abstract property name: str
Plotter name
- property x_: numpy.ndarray
- property y_: numpy.ndarray
- class ternary_diagram.ternary_diagram._ContourPlotter(vector, ax=None, z=None, z_min=None, z_max=None, fill: bool = True, flag_cbar: bool = True, **kwargs)
Bases:
ternary_diagram.ternary_diagram._BasePlotter
This is a base class for the wrapper of matplotlib.pyplot. functions.
- Parameters
vector (ArrayLike) – vector
ax (Optional[matplotlib.axes.Axes], optional) – , by default None
z (Optional[ArrayLike], optional) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
- property name
Plotter name
- class ternary_diagram.ternary_diagram._LinePlotter(vector, ax=None, **kwargs)
Bases:
ternary_diagram.ternary_diagram._BasePlotter
This is a base class for the wrapper of matplotlib.pyplot. functions.
- Parameters
vector (ArrayLike) – vector
ax (Optional[matplotlib.axes.Axes], optional) – , by default None
z (Optional[ArrayLike], optional) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
- property name
Plotter name
- class ternary_diagram.ternary_diagram._ScatterPlotter(vector, ax=None, z=None, z_min=None, z_max=None, annotations=None, flag_cbar: bool = True, **kwargs)
Bases:
ternary_diagram.ternary_diagram._BasePlotter
This is a base class for the wrapper of matplotlib.pyplot. functions.
- Parameters
vector (ArrayLike) – vector
ax (Optional[matplotlib.axes.Axes], optional) – , by default None
z (Optional[ArrayLike], optional) – , by default None
z_min (Optional[Number], optional) – , by default None
z_max (Optional[Number], optional) – , by default None
- property name
Plotter name