Note
Click here to download the full example code
Plot Demo
Demonstrating the mass-composition plot methods.
import pandas as pd
import plotly
from plotly.graph_objs import Figure
from elphick.mass_composition.datasets.sample_data import sample_data
from elphick.mass_composition import MassComposition
Create a MassComposition object
We get some demo data in the form of a pandas DataFrame
df_data: pd.DataFrame = sample_data()
print(df_data.head())
wet_mass mass_dry FE SIO2 al2o3 LOI group
index
0 100.0 90.0 57.0 5.2 3.0 5.0 grp_1
1 90.0 80.0 59.0 3.1 1.7 4.0 grp_1
2 110.0 90.0 61.0 2.2 0.9 3.0 grp_2
Construct a MassComposition object and standardise the chemistry variables
obj_mc: MassComposition = MassComposition(df_data)
print(obj_mc)
unnamed
<xarray.Dataset> Size: 216B
Dimensions: (index: 3)
Coordinates:
* index (index) int64 24B 0 1 2
Data variables:
mass_wet (index) float64 24B 100.0 90.0 110.0
mass_dry (index) float64 24B 90.0 80.0 90.0
H2O (index) float64 24B 10.0 11.11 18.18
Fe (index) float64 24B 57.0 59.0 61.0
SiO2 (index) float64 24B 5.2 3.1 2.2
Al2O3 (index) float64 24B 3.0 1.7 0.9
LOI (index) float64 24B 5.0 4.0 3.0
group (index) object 24B 'grp_1' 'grp_1' 'grp_2'
Attributes:
mc_name: unnamed
mc_vars_mass: ['mass_wet', 'mass_dry']
mc_vars_chem: ['Fe', 'SiO2', 'Al2O3', 'LOI']
mc_vars_attrs: ['group']
mc_interval_edges: {}
Create an interactive parallel plot
fig: Figure = obj_mc.plot_parallel()
fig
Create an interactive parallel plot with only the components
fig2 = obj_mc.plot_parallel(vars_include=['mass_wet', 'H2O', 'Fe'])
fig2
Create a parallel plot with color
fig3 = obj_mc.plot_parallel(color='group')
fig3
Create a ternary diagram for 3 composition variables
fig4 = obj_mc.plot_ternary(variables=['SiO2', 'Al2O3', 'LOI'], color='group')
# noinspection PyTypeChecker
plotly.io.show(fig4) # this call to show will set the thumbnail for use in the gallery
Total running time of the script: ( 0 minutes 1.445 seconds)