def make9of100ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig = pylab.figure(figsize=(8, 6)) axl = [] for i in [1, 4, 7, 2, 5, 8, 3, 6, 9]: axl += [fig.add_subplot(3, 3, i)] fig.subplots_adjust(left=0.05, right=.8, bottom=.05, top=.95, hspace=.08, wspace=.08) stpl = [] xpos = [.27] * 9 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<4: stp.ax.text(xp, .8, '%s$_{%.2f}$' % (ellabels[3], (count * .01)), ha='right', va='center', fontsize=15) #else: # stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.2), 1), ha='right', va='center', fontsize=17) return axl, stpl
def make10ternaxes(ellabels=['A', 'B', 'C', 'D']): ax_xc=[] ax_yc=[] xcdel=[.22, .2, .1, .04, .04, .04, .03, .03, .03, .03] ax_yc=[.5, .6, .36, .65, .49, .33, .68, .55, .43, .31, .2] for i in range(10): if i==0: ax_xc+=[xcdel[i]] else: ax_xc+=[ax_xc[-1]+xcdel[i]] #ax_yc+=[.5+((i%2)*2.-1.)*((i>0)*.1+.072*i/10)] shape1=numpy.array([.35, 1.]) fig=pylab.figure(figsize=(12, 8)) axl=[] for i, xc, yc in zip(range(1, 11), ax_xc, ax_yc): w, l=shape1/i axl+=[fig.add_axes([xc-w/2, yc-l/2, w, l])] stpl=[] for count, ax in enumerate(axl): stp=TernaryPlot(ax, ellabels=ellabels[:3]) stp.label() stpl+=[stp] if count<9: stp.ax.text(.3, .8, '%s$_{%.2f-%.2f}$' %(ellabels[3], (count*.1), ((count+1)*.1)-.01), ha='right', va='center') else: stp.ax.text(.3, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.1), 1), ha='right', va='center') return axl, stpl
def make30ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig = pylab.figure(figsize=(14, 8)) axl = [] delw = .02 delh = .04 yscalefct = [1.] * 6 #[.7, .7, .7, .7, .7, .7] xscalefct = [1., .9, .67, .67, .67, .67] npercol = numpy.array([3, 4, 5, 6, 6, 6]) colw = (1. / npercol) colw[0] *= .85 colw[1] *= .9 colw = (colw / colw.sum()) * (.9 - 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] * 30 # 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 < 29: stp.ax.text(xp, .8, '%s$_{%.2f}$' % (ellabels[3], (count * .0333)), ha='right', va='center', fontsize=17) else: stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' % (ellabels[3], (count * .0333), 1), ha='right', va='center', fontsize=17) return axl, stpl
def make10ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None, fontsize=17): if fig is None: fig = pylab.figure(figsize=(12, 8)) ax_xc = [] ax_yc = [] xcdel = [.18, .19, .065, .1, .04, .05, .055, .03, .02, .02] ax_yc = [.49, .68, .30, .74, .48, .24, .78, .58, .39, .21] for i in range(10): if i == 0: ax_xc += [xcdel[i]] else: ax_xc += [ax_xc[-1] + xcdel[i]] #ax_yc+=[.5+((i%2)*2.-1.)*((i>0)*.1+.072*i/10)] shape1 = numpy.array([.35, 1.]) scales = [.82, 0.51, 0.39, 0.3, 0.22, 0.2, 0.17, 0.14, 0.11, 0.09] axl = [] for sc, xc, yc in zip(scales, ax_xc, ax_yc): w, l = shape1 * sc axl += [fig.add_axes([xc - w / 2, yc - l / 2, w, l])] stpl = [] xpos = [.27] * 10 xpos[0:3] = [.38, .36, .33] xpos[-1] = .18 for count, (ax, xp) in enumerate(zip(axl, xpos)): stp = TernaryPlot(ax, ellabels=ellabels[:3], offset=.03) if not fontsize is None: stp.label( fontsize=fontsize) #,fontdict={'fontname':'Times New Roman'}) stpl += [stp] if not fontsize is None: if count < 9: stp.ax.text(xp, .8, '%s$_{%.2f-%.2f}$' % (ellabels[3], (count * .1), ((count + 1) * .1) - .01), ha='right', va='center', fontsize=fontsize) else: stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' % (ellabels[3], (count * .1), 1), ha='right', va='center', fontsize=fontsize) return axl, stpl
def make4ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig = pylab.figure(figsize=(12, 5)) w = .21 h = .9 axl = [] for i in range(4): axl += [fig.add_axes([.02 + i * (w + .01), (1. - h) / 2., w, h])] stpl = [] for i, ax in zip([3, 2, 1, 0], axl): eltemp = copy.copy(ellabels) eltemp.pop(i) stp = TernaryPlot(ax, ellabels=eltemp) stp.label() stpl += [stp] return axl, stpl
def make4ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig=pylab.figure(figsize=(12, 5)) w=.21 h=.9 axl=[] for i in range(4): axl+=[fig.add_axes([.02+i*(w+.01), (1.-h)/2., w, h])] stpl=[] for i, ax in zip([3, 2, 1, 0], axl): eltemp=copy.copy(ellabels) eltemp.pop(i) stp=TernaryPlot(ax, ellabels=eltemp) stp.label() stpl+=[stp] return axl, stpl
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 make10ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None, fontsize=17): if fig is None: fig=pylab.figure(figsize=(12, 8)) ax_xc=[] ax_yc=[] xcdel=[.18, .19, .065, .1, .04, .05, .055, .03, .02, .02] ax_yc=[.49, .68, .30, .74, .48, .24, .78, .58, .39, .21] for i in range(10): if i==0: ax_xc+=[xcdel[i]] else: ax_xc+=[ax_xc[-1]+xcdel[i]] #ax_yc+=[.5+((i%2)*2.-1.)*((i>0)*.1+.072*i/10)] shape1=numpy.array([.35, 1.]) scales=[.82, 0.51, 0.39, 0.3, 0.22, 0.2, 0.17, 0.14, 0.11, 0.09] axl=[] for sc, xc, yc in zip(scales, ax_xc, ax_yc): w, l=shape1*sc axl+=[fig.add_axes([xc-w/2, yc-l/2, w, l])] stpl=[] xpos=[.27]*10 xpos[0:3]=[.38, .36, .33] xpos[-1]=.18 for count, (ax, xp) in enumerate(zip(axl, xpos)): stp=TernaryPlot(ax, ellabels=ellabels[:3], offset=.03) if not fontsize is None: stp.label(fontsize=fontsize)#,fontdict={'fontname':'Times New Roman'}) stpl+=[stp] if not fontsize is None: if count<9: stp.ax.text(xp, .8, '%s$_{%.2f-%.2f}$' %(ellabels[3], (count*.1), ((count+1)*.1)-.01), ha='right', va='center', fontsize=fontsize) else: stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.1), 1), ha='right', va='center', fontsize=fontsize) return axl, stpl
def make10ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig=pylab.figure(figsize=(12, 8)) ax_xc=[] ax_yc=[] xcdel=[.22, .19, .1, .04, .04, .05, .03, .03, .03, .03] ax_yc=[.5, .6, .36, .65, .49, .33, .67, .55, .445, .32] for i in range(10): if i==0: ax_xc+=[xcdel[i]] else: ax_xc+=[ax_xc[-1]+xcdel[i]] #ax_yc+=[.5+((i%2)*2.-1.)*((i>0)*.1+.072*i/10)] shape1=numpy.array([.35, 1.]) axl=[] for i, xc, yc in zip(range(1, 11), ax_xc, ax_yc): w, l=shape1/i axl+=[fig.add_axes([xc-w/2, yc-l/2, w, l])] stpl=[] xpos=[.27]*10 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=17)#,fontdict={'fontname':'Times New Roman'}) stpl+=[stp] if count<9: stp.ax.text(xp, .8, '%s$_{%.2f-%.2f}$' %(ellabels[3], (count*.1), ((count+1)*.1)-.01), ha='right', va='center', fontsize=17) else: stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.1), 1), ha='right', va='center', fontsize=17) return axl, stpl
def make9of100ternaxes(ellabels=['A', 'B', 'C', 'D'], fig=None): if fig is None: fig=pylab.figure(figsize=(8, 6)) axl=[] for i in [1, 4, 7, 2, 5, 8, 3, 6, 9]: axl+=[fig.add_subplot(3, 3, i)] fig.subplots_adjust(left=0.05, right=.8, bottom=.05, top=.95, hspace=.08, wspace=.08) stpl=[] xpos=[.27]*9 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<4: stp.ax.text(xp, .8, '%s$_{%.2f}$' %(ellabels[3], (count*.01)), ha='right', va='center', fontsize=15) #else: # stp.ax.text(xp, .8, '%s$_{%.2f-%d}$' %(ellabels[3], (count*.2), 1), ha='right', va='center', fontsize=17) return axl, stpl
from myternaryutility import TernaryPlot import matplotlib.cm as cm import numpy import pylab, copy from colorsys import rgb_to_hsv from colorsys import hsv_to_rgb pylab.figure(figsize=(6, 3)) ax=pylab.gca() #stp = TernaryPlot(ax, ellabels=['Au', 'Cu', 'Si']) stp = TernaryPlot(ax, ellabels=['A', 'B', 'C']) stp.grid(nintervals=10, printticklabels=[4]) stp.label(fontsize=12) comps=numpy.random.rand(50, 3) comps/=comps.sum(axis=1)[:, numpy.newaxis] #compdist=(numpy.random.rand(len(comps), 3)-0.5)/5 comps2=copy.copy(comps) comps2[:, 2]+=.5 comps2/=comps2.sum(axis=1)[:, numpy.newaxis] #compsdiff=comps2-comps # #terncoord=numpy.float64(comps) #terncoord2=numpy.float64(comps2) # # # #sat = ((compsdiff**2).sum(axis=1)/2.)**.5 #
Y = cmp.values / 100 #define subset Xsubset, Ysubset that is fed to the GPR model #and Xfit where fitting is done x = np.linspace(np.min(X[:, 0]), np.max(X[:, 0]), 50) y = np.linspace(np.min(X[:, 1]), np.max(X[:, 1]), 50) xv, yv = np.meshgrid(x, y) Xfit_ = np.array([xv.flatten(), yv.flatten()]) idx = [] for i in range(len(Xfit_.T)): if is_in_hull(Xfit_[:, i], X): idx.append(i) Xfit = Xfit_[:, idx] #%% Predict using gaussian process regressor kernel = RBF([1.0]) + WhiteKernel(noise_level=0.0336) gpr = GaussianProcessRegressor(kernel=kernel) gpr.fit(Xsubset, Ysubset) Ygpr, Ystd = gpr.predict(Xfit.T, return_std=True) #%% plot predictions ax = pylab.gca() stp = TernaryPlot(ax, ellabels=cmp.columns) x, y = stp.toCart(Ygpr) plt.scatter(x, y, s=10, c=Ystd) stp.label(fontsize=16) plt.colorbar() plt.show()
data=[(cell, xv, yv, zv,0., cv) for cell, xv, yv, zv, cv in zip(range(1,26),x, y, z, comp) if len(zv)>0] cells=numpy.array(map(operator.itemgetter(0), data)) enth=map(operator.itemgetter(1), data) coolrate=map(operator.itemgetter(2), data) za=numpy.array(map(operator.itemgetter(3), data)) garb=numpy.float32(map(operator.itemgetter(4), data)) ca=numpy.array(map(operator.itemgetter(5), data)) title=r'Film thickness (nm)' #********start ternary plotting pylab.figure(figsize=(10, 6)) ax=pylab.subplot(111) ##stp = TernaryPlot(ax, ellabels=['Au', 'Si', 'Cu']) stp = TernaryPlot(ax, ellabels=['Au', 'Si', 'Cu'], minlist=[0.47, 0.12, .2]) stp.grid(nintervals=3) stp.label(fontsize=14) #plot za value from above by color stp.scatter(ca, s=80, c=za, label='_', cmap=cm.jet, alpha=1., marker='o') #scatter doesn't work well with legend, so label="_" (hides it); cmap chooses the color scheme; alpha allows some transparency to see overlapping data stp.colorbar(title, fontsize=14) #stp.ax.set_title(title, fontsize=14) #**** ##plot cellnumbers #celllist=[1, 2]+range(4, 21)+[22]+[24, 25] #for selectcell in celllist: # stp.text(comp[selectcell-1], `selectcell`, ha='center', va='center', color='r', fontsize=12)
]) comps = numpy.array([au, cu, si]).T comps = numpy.array([c / c.sum() for c in comps]) aumin = comps[:, 0].min() cumin = comps[:, 1].min() simin = comps[:, 2].min() pylab.figure(figsize=(6, 3)) ax = pylab.gca() #stp = TernaryPlot(ax, ellabels=['Au', 'Cu', 'Si']) stp = TernaryPlot(ax, ellabels=['Au', 'Cu', 'Si'], minlist=[aumin, cumin, simin]) stp.grid(nintervals=10, printticklabels=[4]) stp.label(fontsize=12) stp.colorcompplot(comps, '.', markersize=9) colors = stp.color_comp_calc(comps) pylab.figure(figsize=(4, 4)) #pylab.scatter(x, y, c=colors, s=40) for xv, yv, c in zip(x, y, colors): pylab.plot([xv], [yv], '.', color=c, ms=12) pylab.gca().set_aspect(1) rmax = numpy.max(x**2 + y**2)**.5 rlab = rmax + 1.5 pylab.text(rlab, 0., 'Au', fontsize=12, color='r', ha='center', va='center') pylab.text(-0.5 * rlab, -0.5 * 3.**.5 * rlab, 'Cu', fontsize=12,
#convert the end members and pairs of endpts to cartesian xy_lineendpairs=[numpy.array(q.toCart(ls)).T for ls in lineendpairs] xy_endmembers=numpy.array(q.toCart(endmembers)).T #choose the composition of a phase and draw the trivial phase field lines phcomp=numpy.array([.5, .3, .2]) q.scatter([phcomp], c='r', s=20) for i in range(3): a=copy.copy(z) a[i]=1. q.line(a, phcomp, fmt='r-') # iterate over all 4 phase field triangular boundaries (triangle defined by 3 points, the phase p0 and 2 end members p1,p2) and all 4 composition lines. find intersections p0=numpy.array(q.toCart([phcomp])).T[0] xy_intr_dlist=[] for countends, (p1) in enumerate(xy_endmembers): for countlines, (l0, l1) in enumerate(xy_lineendpairs): xy_intr, interbool=interwithinsegs(p0, p1, l0, l1) if interbool: xy_intr_dlist+=[dict({}, xy_intr=xy_intr, xy_lineends=(l0, l1), index_endmems=countends, index_lineends=countlines)] q.scatter(q.toComp([xy_intr]), c='g', s=20) q.label(fontsize=16) pylab.show()
xy_lineendpairs = [numpy.array(q.toCart(ls)).T for ls in lineendpairs] xy_endmembers = numpy.array(q.toCart(endmembers)).T #choose the composition of a phase and draw the trivial phase field lines phcomp = numpy.array([.5, .3, .2]) q.scatter([phcomp], c='r', s=20) for i in range(3): a = copy.copy(z) a[i] = 1. q.line(a, phcomp, fmt='r-') # iterate over all 4 phase field triangular boundaries (triangle defined by 3 points, the phase p0 and 2 end members p1,p2) and all 4 composition lines. find intersections p0 = numpy.array(q.toCart([phcomp])).T[0] xy_intr_dlist = [] for countends, (p1) in enumerate(xy_endmembers): for countlines, (l0, l1) in enumerate(xy_lineendpairs): xy_intr, interbool = interwithinsegs(p0, p1, l0, l1) if interbool: xy_intr_dlist += [ dict({}, xy_intr=xy_intr, xy_lineends=(l0, l1), index_endmems=countends, index_lineends=countlines) ] q.scatter(q.toComp([xy_intr]), c='g', s=20) q.label(fontsize=16) pylab.show()