pycalphad.plot.binary package¶
Submodules¶
pycalphad.plot.binary.compsets module¶

class
pycalphad.plot.binary.compsets.
BinaryCompset
(phase_name, temperature, indep_comp, composition, site_fracs)[source]¶ Bases:
object
Composition set for representations of a phase equilibria in a two component system with a temperature condition.
 Parameters
phase_name (str) – Name of phase
temperature (float) – Temperature corresponding the the calculation
indep_comp (str) – Name of the independent component
composition (float) – Mole fraction of the independent component
site_fracs (np.ndarray) – Array of floats corresponding to the site fractions.
Notes
In the future, this representation could be phased out if equilibrium returned composition sets.

SITE_FRAC_ATOL
= 0.001¶

TEMPERATURE_ATOL
= 0.1¶

class
pycalphad.plot.binary.compsets.
CompsetPair
(compsets)[source]¶ Bases:
object
Pair of binary composition sets that make up an equilibrium
 Parameters
compsets (list of BinaryCompset) –

compsets
¶ CompSets sorted by composition
 Type
list of BinaryCompset

a
¶ Composition set in the pair with the lower composition
 Type

b
¶ Composition set in the pair with the higher composition
 Type

phases
¶ List of phase names, sorted by composition
 Type
list of str

unique_phases
¶ Set of phase names
 Type
set of str

compositions
¶ Array of compositions, sorted
 Type
np.ndarray

temperature
¶ Temperature of the 2D compsets
 Type
float

same_phase
¶ Whether the composition sets are for the same phase
 Type
bool

mean_composition
¶ Mean composition of the CompSets
 Type
float

max_composition
¶ Max composition of the CompSets
 Type
float

min_composition
¶ Min composition of the CompSets
 Type
float

Tdiscrepancy
(other)[source]¶ Calculate the temperature discrepancy (absolute difference) between this pair of composition sets and another.
 Parameters
other (CompsetPair) –
 Returns
 Return type
np.float64

pairwise_xdiscrepancy
(other)[source]¶ Compute the ordered composition discrepancy between this and another pair of CompSet2D objects.
 Parameters
other (CompsetPair) –
 Returns
 Return type
float

xdiscrepancy
(ignore_phase=False)[source]¶ Calculate the composition discrepancy (absolute difference) between this composition set and another.
 Parameters
ignore_phase (bool) – If False, unlike phases will give infinite discrepancy. If True, we only care about the composition and the real discrepancy will be returned.
 Returns
 Return type
np.float64

pycalphad.plot.binary.compsets.
find_two_phase_region_compsets
(hull, temperature, indep_comp, indep_comp_idx, misc_gap_tol=0.1, minimum_composition=None)[source]¶ From a 1D convex hull at constant T and P, return the composition sets for a two phase region or that have the smallest index composition coordinate
 Parameters
hull (EquilibriumResult) – Equilibriumlike from pycalphad that has a Phase Data variable.
temperature (float) – Temperature that the calculation was performed at
indep_comp (str) – Name of the independent component
indep_comp_idx (str) – Index of the independent component in the the sorted pure elements
misc_gap_tol (float) – If any site fractions are different by at least this amount, the composition sets are considered distinct and in a miscibility gap.
minimum_composition (float) – Minimum composition in the convex hull to search for composition sets
 Returns
 Return type
pycalphad.plot.binary.map module¶

pycalphad.plot.binary.map.
map_binary
(dbf, comps, phases, conds, eq_kwargs=None, calc_kwargs=None, boundary_sets=None, verbose=False, summary=False)[source]¶ Map a binary TX phase diagram
 Parameters
dbf (Database) –
comps (list of str) –
phases (list of str) – List of phases to consider in mapping
conds (dict) – Dictionary of conditions
eq_kwargs (dict) – Dictionary of keyword arguments to pass to equilibrium
verbose (bool) – Print verbose output for mapping
boundary_sets (ZPFBoundarySets) – Existing ZPFBoundarySets
 Returns
 Return type
Notes
Assumes conditions in T and X.
Simple algorithm to map a binary phase diagram in TX. More or less follows the algorithm described in Figure 2 by Snider et al. [1] with the small algorithmic improvement of constructing a convex hull to find the next potential two phase region.
For each temperature, proceed along increasing composition, skipping two over two phase regions, once calculated. [1] J. Snider, I. Griva, X. Sun, M. Emelianenko, Set based framework for
Gibbs energy minimization, Calphad. 48 (2015) 1826. doi: 10.1016/j.calphad.2014.09.005
pycalphad.plot.binary.plot module¶
The plot module handles plotting ZPF boundaries and provides a userfacing function binplot for users to plot binary phase diagrams with a similar API as equilibrium.

pycalphad.plot.binary.plot.
binplot
(database, components, phases, conditions, plot_kwargs=None, **map_kwargs)[source]¶ Calculate the binary isobaric phase diagram.
This function is a convenience wrapper around map_binary() and plot_boundaries()
 Parameters
database (Database) – Thermodynamic database containing the relevant parameters.
components (list) – Names of components to consider in the calculation.
phases (list) – Names of phases to consider in the calculation.
conditions (dict) – Maps StateVariables to values and/or iterables of values. For binplot only one changing composition and one potential coordinate each is supported.
eq_kwargs (dict, optional) – Keyword arguments to use in equilibrium() within map_binary(). If eq_kwargs is defined in map_kwargs, this argument takes precedence.
map_kwargs (dict, optional) – Additional keyword arguments to map_binary().
plot_kwargs (dict, optional) – Keyword arguments to plot_boundaries().
 Returns
Matplotlib Axes of the phase diagram
 Return type
Axes
Examples
None yet.

pycalphad.plot.binary.plot.
plot_boundaries
(zpf_boundary_sets, tielines=True, scatter=True, ax=None, gridlines=False)[source]¶ Plot a set of ZPFBoundarySets
 Parameters
zpf_boundary_sets (pycalphad.mapping.zpf_boundary_sets.ZPFBoundarySets) –
tielines (optional, bool) – Whether the plot the tielines (defaults to True)
scatter (optional, bool) – Whether to use scatter plot the phase boundaries (True, the default) or to connect lines in the same two phase region by lines. Note that lines may appear broken when the set of phases change, even if the boundary does not change.
ax (plt.Axes) – Matplotlib axes to plot to. If none are pasesed, a new figure will be created.
gridlines (False) – Whether to plot the grid lines in the plot. Defaults to False.
 Returns
 Return type
plt.Axes
pycalphad.plot.binary.zpf_boundary_sets module¶

class
pycalphad.plot.binary.zpf_boundary_sets.
TwoPhaseRegion
(initial_compsets)[source]¶ Bases:
object
A group of points that belong to the same phase region.

phases
¶ Unique phases in this two phase region
 Type
frozenset

compsets
¶  Type
list of CompsetPair

add_compsets
(compset_pair)[source]¶ Add composition sets to this region.
 Parameters
pair (CompsetPair) – Add a CompsetPair to the list of composition sets
Notes
For performance reasons (checking whether the CompsetPair belongs has a complexity of O(N)), users are responsible for determining if the compsets belong in this TwoPhaseRegion.

compsets_belong_in_region
(compsets, Xtol=0.05, Ttol=10)[source]¶ Return True if the composition sets belong to this TwoPhaseRegion
 Parameters
compsets (CompsetPair) –
Xtol (float) – Composition discrepancy tolerance
Ttol (float) – Temperature discrepancy tolerance
 Returns
 Return type
bool
Notes
A new CompsetPair object belongs in the this region if, when compared to the most recently added CompsetPair: 1. All the phases are the same (in the same order) 2. The composition discrepancies between BinaryCompsets of the same
phase are below Xtol
The temperature discrepancy between the CompsetPairs is below Ttol


class
pycalphad.plot.binary.zpf_boundary_sets.
ZPFBoundarySets
(comps, indep_composition_condition)[source]¶ Bases:
object
Holds CompsetPairs that can be organized into TwoPhaseRegions and plotted together.

components
¶ List of components
 Type
list of str

indep_comp_cond
¶ Condition for the independent component
 Type
v.X

all_compsets
¶  Type
list of CompsetPair

two_phase_regions
¶  Type
list of TwoPhaseRegion

add_compsets
(compsets, Xtol=0.05, Ttol=10)[source]¶ Add composition sets to current boundary sets
 Parameters
compsets (CompsetPair) –

get_line_plot_boundaries
(close_miscibility_gaps=0.05)[source]¶ Get the ZPF boundaries to plot from each two phase region.
 Parameters
close_miscibility_gaps (float, optional) –
 If a float is passed, add a line segment between compsets at the top
or bottom of a two phase region if the discrepancy is below a tolerance. If None is passed, do not close the gap.
Notes
For now, we will not support connecting regions with lines, so this function returns a tuple of scatter_dict and a tineline_collection.
Examples
>>> boundary_collection, tieline_collection, legend_handles = zpf_boundary_sets.get_line_plot_boundaries() >>> ax.add_collection(boundary_collection) >>> ax.add_collection(tieline_collection) >>> ax.legend(handles=legend_handles)
 Returns
 Return type
(line_collections, tieline_collection, legend_handles)

get_scatter_plot_boundaries
()[source]¶ Get the ZPF boundaries to plot from each two phase region.
Notes
For now, we will not support connecting regions with lines, so this function returns a tuple of scatter_dict and a tineline_collection.
Examples
>>> scatter_dict, tieline_collection, legend_handles = zpf_boundary_sets.get_scatter_plot_boundaries() >>> ax.scatter(**scatter_dict) >>> ax.add_collection(tieline_collection) >>> ax.legend(handles=legend_handles)
 Returns
 Return type
(scatter_dict, tieline_collection, legend_handles)
