#!/usr/bin/env python # coding: utf-8 # ## ternary_contour figure factory # The ternary contour figure factory has been updated to use the plotly.js ternary coordinate system # In[1]: import numpy as np import plotly.figure_factory as ff import plotly print(plotly.__version__) from plotly.offline import init_notebook_mode, iplot init_notebook_mode() # ## Function with one maximum # In[2]: a, b = np.mgrid[0:1:20j, 0:1:20j] mask = a + b <= 1 a = a[mask].ravel() b = b[mask].ravel() c = 1 - a - b z = a * b * c z /= z.max() # Default parameters # In[3]: fig = ff.create_ternary_contour(np.stack((a, b, c)), z) iplot(fig) # Show colorbar # In[4]: fig = ff.create_ternary_contour(np.stack((a, b, c)), z, showscale=True) iplot(fig) # Show markers where contour is defined # In[5]: fig = ff.create_ternary_contour(np.stack((a, b, c)), z, showscale=True, showmarkers=True) iplot(fig) # Show contours as lines and specify the number of contours # In[6]: fig2 = ff.create_ternary_contour( np.stack((a, b, c)), z, ncontours=8, showmarkers=True, showscale=True, coloring='lines') iplot(fig2) # ## Datasets with several local extrema # # Also specify cartesian interpolation # In[7]: x, y = np.mgrid[0:1:20j, 0:1:20j] mask = x + y <= 1 x = x[mask] y = y[mask] data = np.stack((x, y, 1 - x - y)) z = np.sin(3.2 * np.pi * (x + y)) + np.sin(3 * np.pi * (x - y)) z3 = np.sin(4 * np.pi * (x + y)) + 0.4 * x # In[8]: fig_per = ff.create_ternary_contour( data, z, ncontours=8, showmarkers=False, showscale=True, colorscale='Viridis', interp_mode='cartesian') iplot(fig_per) # In[9]: contour_data = np.array([ [0. , 1. , 0. , 1.27036107], [0.3 , 0.1 , 0.6 , 1.27893858], [0.25 , 0.45 , 0.3 , 0.52255697], [0.34 , 0.56 , 0.1 , 1.50035059], [0. , 0. , 1. , 0.84853798], [0.4 , 0.5 , 0.1 , 1.27722501], [0.65 , 0.3 , 0.05 , 1.20920733], [0.05 , 0.75 , 0.2 , 0.88965008], [0. , 0.85 , 0.15 , 0.59293362], [1. , 0. , 0. , 0.9223051 ], [0.47 , 0.33 , 0.2 , 1.57173859], [0.2 , 0.3 , 0.5 , 1.33606612], [0.7 , 0.13 , 0.17 , 1.08977333]]) abc =contour_data[:, :3] z = contour_data[:, 3] fig = ff.create_ternary_contour( 100 * abc.T, z, interp_mode='ilr', coloring=None, pole_labels=['Ab', 'Or', 'An'], showscale=True, ncontours=12, colorscale='Viridis', showmarkers=True) iplot(fig) # In[ ]: