pycalphad.plot package

Subpackages

Submodules

pycalphad.plot.eqplot module

The eqplot module contains functions for general plotting of the results of equilibrium calculations.

pycalphad.plot.eqplot.eqplot(eq, ax=None, x=None, y=None, z=None, tielines=True, tieline_color=(0, 1, 0, 1), tie_triangle_color=(1, 0, 0, 1), legend_generator=<function phase_legend>, **kwargs)[source]

Plot the result of an equilibrium calculation.

The type of plot is controlled by the degrees of freedom in the equilibrium calculation.

Parameters
  • eq (xarray.Dataset) – Result of equilibrium calculation.

  • ax (matplotlib.Axes) – Default axes used if not specified.

  • x (StateVariable, optional) –

  • y (StateVariable, optional) –

  • z (StateVariable, optional) –

  • tielines (bool) – If True, will plot tielines

  • tieline_color (color) – A valid matplotlib color, such as a named color string, hex RGB string, or a tuple of RGBA components to set the color of the two phase region tielines. The default is an RGBA tuple for green: (0, 1, 0, 1).

  • tie_triangle_color (color) – A valid matplotlib color, such as a named color string, hex RGB string, or a tuple of RGBA components to set the color of the two phase region tielines. The default is an RGBA tuple for red: (1, 0, 0, 1).

  • legend_generator (Callable) – A function that will be called with the list of phases and will return legend labels and colors for each phase. By default pycalphad.plot.utils.phase_legend is used

  • kwargs (kwargs) – Passed to matplotlib.pyplot.scatter.

Return type

matplotlib AxesSubplot

pycalphad.plot.ternary module

The ternary module enables plotting of ternary isobaric phase diagrams.

pycalphad.plot.ternary.ternplot(dbf, comps, phases, conds, x=None, y=None, eq_kwargs=None, **plot_kwargs)[source]

Calculate the ternary isothermal, isobaric phase diagram. This function is a convenience wrapper around equilibrium() and eqplot().

Parameters
  • dbf (Database) – Thermodynamic database containing the relevant parameters.

  • comps (list) – Names of components to consider in the calculation.

  • phases (list) – Names of phases to consider in the calculation.

  • conds (dict) – Maps StateVariables to values and/or iterables of values. For ternplot only one changing composition and one potential coordinate each is supported.

  • x (v.MoleFraction) – instance of a pycalphad.variables.composition to plot on the x-axis. Must correspond to an independent condition.

  • y (v.MoleFraction) – instance of a pycalphad.variables.composition to plot on the y-axis. Must correspond to an independent condition.

  • eq_kwargs (optional) – Keyword arguments to equilibrium().

  • plot_kwargs (optional) – Keyword arguments to eqplot().

Return type

A phase diagram as a figure.

Examples

None yet.

pycalphad.plot.triangular module

Register a 'triangular' projection with matplotlib to plot diagrams on triangular axes.

Users should not have to instantiate the TriangularAxes class directly. Instead, the projection name can be passed as a keyword argument to matplotlib.

>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> plt.gca(projection='triangular')
>>> plt.scatter(np.random.random(10), np.random.random(10))
class pycalphad.plot.triangular.TriangularAxes(*args, **kwargs)[source]

Bases: matplotlib.axes._axes.Axes

A custom class for triangular projections.

can_zoom()[source]

Return True if this axes support the zoom box

cla()[source]

Hard-code axes limits to be on [0, 1] for both axes.

Warning: Limits not on [0, 1] may lead to clipping issues!

drag_pan(button, key, x, y)[source]

Called when the mouse moves during a pan operation.

Parameters
  • button (.MouseButton) – The pressed mouse button.

  • key (str or None) – The pressed key, if any.

  • x (float) – The mouse coordinates in display coords.

  • y (float) – The mouse coordinates in display coords.

Notes

This is intended to be overridden by new projection types.

end_pan()[source]

Called when a pan operation completes (when the mouse button is up.)

Notes

This is intended to be overridden by new projection types.

get_xaxis_text1_transform(pad)[source]
Returns

  • transform (Transform) – The transform used for drawing x-axis labels, which will add pad_points of padding (in points) between the axis and the label. The x-direction is in data coordinates and the y-direction is in axis coordinates

  • valign ({‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}) – The text vertical alignment.

  • halign ({‘center’, ‘left’, ‘right’}) – The text horizontal alignment.

Notes

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

get_xaxis_text2_transform(pad)[source]
Returns

  • transform (Transform) – The transform used for drawing secondary x-axis labels, which will add pad_points of padding (in points) between the axis and the label. The x-direction is in data coordinates and the y-direction is in axis coordinates

  • valign ({‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}) – The text vertical alignment.

  • halign ({‘center’, ‘left’, ‘right’}) – The text horizontal alignment.

Notes

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

get_xaxis_transform(which='grid')[source]

Get the transformation used for drawing x-axis labels, ticks and gridlines. The x-direction is in data coordinates and the y-direction is in axis coordinates.

Note

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

get_yaxis_text1_transform(pad)[source]
Returns

  • transform (Transform) – The transform used for drawing y-axis labels, which will add pad_points of padding (in points) between the axis and the label. The x-direction is in axis coordinates and the y-direction is in data coordinates

  • valign ({‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}) – The text vertical alignment.

  • halign ({‘center’, ‘left’, ‘right’}) – The text horizontal alignment.

Notes

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

get_yaxis_text2_transform(pad)[source]
Returns

  • transform (Transform) – The transform used for drawing secondart y-axis labels, which will add pad_points of padding (in points) between the axis and the label. The x-direction is in axis coordinates and the y-direction is in data coordinates

  • valign ({‘center’, ‘top’, ‘bottom’, ‘baseline’, ‘center_baseline’}) – The text vertical alignment.

  • halign ({‘center’, ‘left’, ‘right’}) – The text horizontal alignment.

Notes

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

get_yaxis_transform(which='grid')[source]

Get the transformation used for drawing y-axis labels, ticks and gridlines. The x-direction is in axis coordinates and the y-direction is in data coordinates.

Note

This transformation is primarily used by the ~matplotlib.axis.Axis class, and is meant to be overridden by new kinds of projections that may need to place axis elements in different locations.

name = 'triangular'
set(*, adjustable=<UNSET>, agg_filter=<UNSET>, alpha=<UNSET>, anchor=<UNSET>, animated=<UNSET>, aspect=<UNSET>, autoscale_on=<UNSET>, autoscalex_on=<UNSET>, autoscaley_on=<UNSET>, axes_locator=<UNSET>, axisbelow=<UNSET>, box_aspect=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, facecolor=<UNSET>, frame_on=<UNSET>, gid=<UNSET>, in_layout=<UNSET>, label=<UNSET>, navigate=<UNSET>, path_effects=<UNSET>, picker=<UNSET>, position=<UNSET>, prop_cycle=<UNSET>, rasterization_zorder=<UNSET>, rasterized=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, title=<UNSET>, transform=<UNSET>, url=<UNSET>, visible=<UNSET>, xbound=<UNSET>, xlabel=<UNSET>, xlim=<UNSET>, xmargin=<UNSET>, xscale=<UNSET>, xticklabels=<UNSET>, xticks=<UNSET>, ybound=<UNSET>, ylabel=<UNSET>, ylim=<UNSET>, ymargin=<UNSET>, yscale=<UNSET>, yticklabels=<UNSET>, yticks=<UNSET>, zorder=<UNSET>)

Set multiple properties at once.

Supported properties are

Properties:

adjustable: {‘box’, ‘datalim’} agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array alpha: scalar or None anchor: (float, float) or {‘C’, ‘SW’, ‘S’, ‘SE’, ‘E’, ‘NE’, …} animated: bool aspect: {‘auto’, ‘equal’} or float autoscale_on: bool autoscalex_on: bool autoscaley_on: bool axes_locator: Callable[[Axes, Renderer], Bbox] axisbelow: bool or ‘line’ box_aspect: float or None clip_box: .Bbox clip_on: bool clip_path: Patch or (Path, Transform) or None facecolor or fc: color figure: .Figure frame_on: bool gid: str in_layout: bool label: object navigate: bool navigate_mode: unknown path_effects: .AbstractPathEffect picker: None or bool or float or callable position: [left, bottom, width, height] or ~matplotlib.transforms.Bbox prop_cycle: unknown rasterization_zorder: float or None rasterized: bool sketch_params: (scale: float, length: float, randomness: float) snap: bool or None title: str transform: .Transform url: str visible: bool xbound: unknown xlabel: str xlim: (bottom: float, top: float) xmargin: float greater than -0.5 xscale: {“linear”, “log”, “symlog”, “logit”, …} or .ScaleBase xticklabels: unknown xticks: unknown ybound: unknown ylabel: str ylim: (bottom: float, top: float) ymargin: float greater than -0.5 yscale: {“linear”, “log”, “symlog”, “logit”, …} or .ScaleBase yticklabels: unknown yticks: unknown zorder: float

set_ylabel(ylabel, fontdict=None, labelpad=None, *, loc=None, **kwargs)[source]

Set the label for the y-axis. Default rotation=60 degrees.

Parameters
  • ylabel (str) – The label text.

  • labelpad (float, default: None) – Spacing in points from the axes bounding box including ticks and tick labels.

  • loc ({‘bottom’, ‘center’, ‘top’}, default: yaxis.labellocation) – The label position. This is a high-level alternative for passing parameters y and horizontalalignment.

  • **kwargs (.Text properties) – .Text properties control the appearance of the label.

See also

text

Documents the properties supported by .Text.

start_pan(x, y, button)[source]

Called when a pan operation has started.

Parameters
  • x (float) – The mouse coordinates in display coords.

  • y (float) – The mouse coordinates in display coords.

  • button (.MouseButton) – The pressed mouse button.

Notes

This is intended to be overridden by new projection types.

pycalphad.plot.utils module

The plot utils module contains some useful routines related to plotting.

pycalphad.plot.utils.phase_legend(phases)[source]

Build matplotlib handles for the plot legend.

Parameters

phases (list) – Names of the phases.

Returns

  • A tuple containing

  • (1) A list of matplotlib handle objects

  • (2) A dict mapping phase names to their RGB color on the plot

Examples

>>> legend_handles, colors = phase_legend(['FCC_A1', 'BCC_A2', 'LIQUID'])

Module contents