def test_transform(self): for tfm, itfm in [ (alr, inverse_alr), (ilr, inverse_ilr), (ILRTransform, None), (ALRTransform, None), ]: with self.subTest(tfm=tfm, itfm=itfm): out = ternary_heatmap(self.data, transform=tfm, inverse_transform=itfm) coords, H, data = out
df = pd.DataFrame(np.array([*get_scatter_points(n=80)]).T, columns=["A", "B", "C"]) df = df.loc[(df > 0.1).all(axis=1), :] ####################################################################################### # From this dataset we'll generate a # :func:`~pyrolite.plot.density.ternary.ternary_heatmap`, which is the basis # for ternary density diagrams via :func:`~pyrolite.plot.pyrochem.density`: # from pyrolite.comp.codata import ILR, inverse_ILR from pyrolite.plot.density.ternary import ternary_heatmap coords, H, data = ternary_heatmap( df.values, bins=10, mode="density", remove_background=True, transform=ILR, inverse_transform=inverse_ILR, grid_border_frac=0.2, ) ####################################################################################### # This function returns more than just the coordinates and histogram/density estimate, # which will come in handy for exploring how it came together. The data variable here # is a dictonary with contains the grids and coordiantes used to construct the # histogram/density diagram. We can use these to show how the ternary log-grid is # constructed, and then transformed back to ternary space before being triangulated # and interpoalted for the ternary heatmap: # import matplotlib.pyplot as plt import pyrolite.plot from pyrolite.util.math import flattengrid
def test_need_inverse_transform(self): for tfm, itfm in [(alr, None), (ilr, None)]: with self.subTest(tfm=tfm, itfm=itfm): out = ternary_heatmap(self.data, transform=tfm, inverse_transform=itfm)
def test_density(self): out = ternary_heatmap(self.data, mode="density") coords, H, data = out self.assertTrue(coords[0].shape == coords[1].shape)
def test_histogram(self): out = ternary_heatmap(self.data, mode="histogram") xe, ye, zi = out coords, H, data = out self.assertTrue(coords[0].shape == coords[1].shape)
def test_default(self): out = ternary_heatmap(self.data) self.assertTrue(isinstance(out, tuple)) coords, H, data = out self.assertTrue(coords[0].shape == coords[1].shape)