pip install scikit-image
conda install -c plotly chart-studio
Plotly referencepip install numpy==1.16.1
the plotly depends on numpy version heavilyfrom scipy.stats import dirichlet
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
from dirichlet import mle
distrib = dirichlet([5, 5, 5])
X = distrib.rvs(1000)
print('shape of the data', X.shape)
alpha = mle(X)
print('estimated alpha, the parameters of Dirichlet distribution',alpha)
shape of the data (1000, 3) estimated alpha, the parameters of Dirichlet distribution [5.02903077 4.98653011 5.06955709]
import plotly as py
import plotly.graph_objs as go
# import numpy as np
x_data = np.linspace(0, 1, 101)
y_data = np.linspace(0, 1, 101)
x_data[:10]
array([0. , 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09])
xx, yy = np.meshgrid(x_data,y_data)
estim = dirichlet(alpha)
def dense(x,y):
if x<=0 or y<=0 or x+y>=1:
return None
else:
return estim.pdf(np.array([x, y, 1-x-y]))
grids = np.array([[x,y,1-x-y] for x,y in zip(xx.ravel(),yy.ravel()) if x>0 and y>0 and x+y<1])
distrib_dense = np.array(list(map(lambda coord: estim.pdf(coord), grids)))
print('grids'' shape', grids.shape, 'distrib_dense length',len(distrib_dense))
grids shape (4851, 3) distrib_dense length 4851
plt.plot(*grids[:,:2],'o')
plt.show()
import plotly.figure_factory as ff
import numpy as np
Al = np.array([0. , 0. , 0., 0., 1./3, 1./3, 1./3, 2./3, 2./3, 1.])
Cu = np.array([0., 1./3, 2./3, 1., 0., 1./3, 2./3, 0., 1./3, 0.])
Y = 1 - Al - Cu
# synthetic data for mixing enthalpy
# See https://pycalphad.org/docs/latest/examples/TernaryExamples.html
enthalpy = (Al - 0.01) * Cu * (Al - 0.52) * (Cu - 0.48) * (Y - 1)**2
fig = ff.create_ternary_contour(np.array([Al, Y, Cu]), enthalpy,
pole_labels=['Al', 'Y', 'Cu'],
interp_mode='cartesian')
print('Note the shapes of the data',np.array([Al, Y, Cu]).shape, enthalpy.shape)
fig.show()
Note the shapes of the data (3, 10) (10,)
x = np.linspace(0,1,101)
y = np.linspace(0,1,101)
xx,yy=np.meshgrid(x,y)
zz = 1-xx-yy
distrib_dense = []
grids=np.array([0,0,0]).reshape(1,-1)
for x,y,z in zip(xx.ravel(),yy.ravel(),zz.ravel()):
if 0<x<1 and 0<y<1 and 0<z<1:
grids = np.concatenate((grids,np.array([x,y,z]).reshape(1,-1)), axis=0)
distrib_dense += [estim.pdf([x,y,z])]
grids = grids[1:,:]
grids.shape, len(distrib_dense)
((4860, 3), 4860)
fig = ff.create_ternary_contour(grids.T, np.array(distrib_dense),
pole_labels=['1st comp.', '2nd comp.', '3rd comp.'],
interp_mode='cartesian')
fig.show()