Multiple diagrams in one figure

Multiple diagrams in one figure#

Import modules

import os

import pandas as pd
import matplotlib.pyplot as plt

from ternary_diagram import TernaryDiagram

Create the figure with layout="constrained". Matplotlib’s constrained layout keeps the diagrams, their labels and the colorbar from overlapping each other, so you don’t need to adjust the layout afterwards or search for a large enough figsize. Pass each Axes to TernaryDiagram with ax=.

fig, axes = plt.subplots(
    1, 2, dpi=72, facecolor="white", figsize=(10, 3.6), layout="constrained"
)
../_images/48f607acedd62a4771acb1b66b5ec0bbc345d4f33f09db5a456ddae5ec01fb4b.png
fpath_example = ".."
fpath_contour = os.path.join(fpath_example, "contour", "example_contour.csv")
fpath_mono_scatter = os.path.join(
    fpath_example, "mono_scatter", "example_mono_scatter.csv"
)
df_contour = pd.read_csv(fpath_contour)
df_mono_scatter = pd.read_csv(fpath_mono_scatter)
display(df_contour.head(), df_mono_scatter.head())
Li2O TiO2 La2O3 z
0 0.0 0.0 50.0 0.000000
1 0.0 1.0 49.0 0.000755
2 0.0 2.0 48.0 0.001509
3 0.0 3.0 47.0 0.002264
4 0.0 4.0 46.0 0.003019
Li2O TiO2 La2O3
0 0 1 9
1 0 2 8
2 0 3 7
3 0 4 6
4 0 5 5
materials = df_contour.columns[0:3]

td1 = TernaryDiagram(materials=materials, ax=axes[0])
td1.contour(vector=df_contour[materials], z=df_contour["z"])

fig
../_images/d06e0a03fd18c22e04f571452d8b2facec89cf0959aaceff545181660614c628.png
materials = df_mono_scatter.columns[0:3]

td2 = TernaryDiagram(materials=materials, ax=axes[1])
td2.scatter(vector=df_mono_scatter[materials])

fig
../_images/b168d7c3c41521bec1f10113c7c76fc6d5fd44de7ed8b218a493f78ca1de1c7a.png
fig.savefig("multiple_figure.png", dpi=144)