import matplotlib.pyplot as plt
from pycalphad import variables as v
from espei.datasets import recursive_glob, load_datasets
from espei.plot import dataplot
# load datasets from directory
= load_datasets(recursive_glob("input-data"))
ds
= ["CU", "MG", "VA"]
components = components[1]
independent_component = ["BCC_A2", "CUMG2", "FCC_A1", "LAVES_C15", "LIQUID"]
phases # Conditions don't need to have valid values.
# Only the keys matter because they are used to search for relevant data.
= {v.P: 101325, v.T: (1,1,1), v.X(independent_component): (1, 1, 1)}
conds
= plt.subplots()
fig, ax =ax)
dataplot(components, phases, conds, ds, ax0, 1)
ax.set_xlim(f"X({independent_component.capitalize()})")
ax.set_xlabel(f"Temperature (K)")
ax.set_ylabel("Cu-Mg Data")
ax.set_title( fig.show()
Plot phase diagram data
Plot data only
When compiling ESPEI datasets of phase equilibria data, it can be useful to plot the data to check that it matches visually with what you are expecting. This script plots data from a binary phase diagram.
Plot phase diagram with data
This example uses binplot
from PyCalphad and dataplot
from ESPEI to plot a phase diagram with the data used to fit it on the same axes.
import matplotlib.pyplot as plt
from pycalphad import Database, binplot, variables as v
from espei.datasets import load_datasets, recursive_glob
from espei.plot import dataplot
# load datasets from directory
= load_datasets(recursive_glob("input-data"))
datasets
# set up the pycalphad phase diagram calculation
= Database("Cr-Ni_mcmc.tdb")
dbf = ["CR", "NI", "VA"]
comps = list(dbf.phases.keys())
phases = {v.P: 101325, v.T: (700, 2200, 10), v.X("CR"): (0, 1, 0.01)}
conds
# plot the phase diagram and data
= plt.subplots()
fig, ax =dict(ax=ax))
binplot(dbf, comps, phases, conds, plot_kwargs=ax)
dataplot(comps, phases, conds, datasets, ax"Cr-Ni MCMC")
ax.set_title(0], conds[v.T][1])
ax.set_ylim(conds[v.T]["X(Cr)")
ax.set_xlabel("Temperature (K)")
ax.set_ylabel( fig.show()