Last active
January 28, 2026 03:26
-
-
Save bocklund/704f7e18e3bb70ec78f595a24a4a2fe9 to your computer and use it in GitHub Desktop.
Plot PyCalphad phase diagram with ESPEI dataplot containing a fixed set of phases.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Plot PyCalphad phase diagram with ESPEI dataplot containing a fixed set of phases. | |
| # The legend generator should have the superset of all modeled phases and all data phases | |
| # (usually this is what causes the colors to mismatch - the phases in the model only come from the model and the dataplot phases come only from the data). | |
| from pycalphad import Database, equilibrium, variables as v, ternplot | |
| from pycalphad.plot.utils import phase_legend | |
| from espei.datasets import load_datasets, recursive_glob | |
| from espei.plot import dataplot | |
| import matplotlib.pyplot as plt | |
| dbf = Database('COST507.tdb') | |
| comps = ['AL', 'MG', 'SI', 'VA'] | |
| phases = list(dbf.phases.keys()) | |
| datasets = load_datasets(recursive_glob("input-data")) | |
| legend_phases = list(dbf.phases.keys()) # + data phases, if applicable | |
| def fixed_legend_generator(phase_names): | |
| # fixed phases and colors | |
| def f(_): | |
| return phase_legend(phase_names) | |
| return f | |
| legend_generator_func = fixed_legend_generator(legend_phases) | |
| conditions = {v.T: 1273, v.P: 101325, v.X('MG'): (0, 1, 0.05), v.X("SI"): (0, 1, 0.05)} | |
| ax = ternplot(dbf, comps, phases, conditions, legend_generator=legend_generator_func) | |
| dataplot(comps, phases, conditions, datasets, legend_generator=legend_generator_func, ax=ax) | |
| plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment