forked from johnmgregoire/PythonCompositionPlots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quaternary_FOM_stackedtern20.py
86 lines (72 loc) · 2.81 KB
/
quaternary_FOM_stackedtern20.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import matplotlib.cm as cm
import numpy
import pylab
import operator, copy, os
#pylab.rc('font',**{'family':'serif''serif':['Times New Roman']})
#pylab.rcParams['font.family']='serif'
#pylab.rcParams['font.serif']='Times New Roman'
pylab.rc('font', family='serif', serif='Times New Roman')
#os.chdir('C:/Users/Gregoire/Documents/PythonCode/ternaryplot')
from myternaryutility import TernaryPlot
from myquaternaryutility import QuaternaryPlot
def make20ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None):
if fig is None:
fig=pylab.figure(figsize=(9, 8))
axl=[]
delw=.02
delh=.04
yscalefct=[1.]*4#[.7, .7, .7, .7, .7, .7]
xscalefct=[1., .9, .67, .67, .67]
npercol=numpy.array([3,4,6,7])
colw=(1./npercol)
colw[0]*=.85
colw[1]*=.9
colw=(colw/colw.sum())*(.85-len(npercol)*delw)
#colw/=colw.sum()
plotcount=0
cumwidth=0
for nc, cw, xsf, ysf in zip(npercol, colw, xscalefct, yscalefct):
w=xsf*cw
h=ysf*((1.-delh*(nc+1))/nc)
cumwidth+=cw+delw
for ic in range(nc):
axl+=[fig.add_axes([cumwidth-cw/2.-w/2., 1.-(delh+ic*(h+delh))-h, w, h])]
stpl=[]
xpos=[.27]*20
# xpos[0:3]=[.35, .29, .28]
# xpos[-1]=.26
for count, (ax, xp) in enumerate(zip(axl, xpos)):
stp=TernaryPlot(ax, ellabels=ellabels[:3], offset=.03)
stp.label(fontsize=15)#,fontdict={'fontname':'Times New Roman'})
stpl+=[stp]
if count<19:
stp.ax.text(xp, .8, '%s$_{%.2f}$' %(ellabels[3], (count*.05)), ha='right', va='center', fontsize=17)
else:
stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.05), 1), ha='right', va='center', fontsize=17)
return axl, stpl
def scatter_20axes(comps, fom, stpl, s=18, cb=False, cbrect=(.86, .3, .03, .4), cblabel='', **kwargs):
abc=comps[:, :3]
abc[abc.sum(axis=1)==0.]=numpy.array([1., 1., 1.])/3.
abc=numpy.array([c/c.sum() for c in abc])
d=comps[:, 3]
d20=numpy.round(d*20.)
d20[d20==20.]=19.
dlims=numpy.array([0., 1., 2., 3.])
marks=[('o', 1., 1.), ('D', .9, .7),('s', .8, .5)]
sl=s*numpy.array([2.3, 1., .58, .38, .38, .42, .38, .46, .8, 1., 1.5]+[1.5]*10)
for i, (stp, sv) in enumerate(zip(stpl, sl)):
inds=numpy.where((d20==i))[0]
#print a, b, len(inds)
if len(inds)>0:
stp.scatter(abc[inds], c=fom[inds], marker='o', s=20, **kwargs)
if cb:
cbax=stp.ax.figure.add_axes(cbrect)
if 'extend' in kwargs.keys():
sm=cm.ScalarMappable(norm=kwargs['norm'], cmap=kwargs['cmap'], extend=kwargs['extend'])
else:
sm=cm.ScalarMappable(norm=kwargs['norm'], cmap=kwargs['cmap'])
sm.set_array(fom)
cb=stp.ax.figure.colorbar(sm, cax=cbax)
cb.set_label(cblabel, fontsize=18)
#make30ternaxes()
#pylab.show()