def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.2, patchscale=1.): self.outlinealpha=outlinealpha self.nint=1.*nintervals self.delta=1./self.nint self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.ax.set_aspect(1.) #self.ax.set_xlim(-.1, 2.6) #self.ax.set_ylim(-.1, 3.**.5/2+.1) self.ax.set_ylim(-.1-3.**.5/4., .1+3.**.5/4.) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.scalefcn=lambda nshell:(self.nint-4.*nshell)/self.nint shift=0. self.shift_nshell=[] for nshell in range(int(self.nint//4)+1): self.shift_nshell+=[shift] shift+=self.delta*2.+2.*self.scalefcn(nshell) self.ax.set_xlim(-.1, shift+self.delta+1.*self.scalefcn(nshell)) self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=patchscale*self.delta/3.**.5,resolution=6, color=c, **kwargs)) if outlinealpha>0: self.outline() if offset is None: self.offset=self.delta self.qindsfortern_skipind=[[1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2]]#sets the order of elements assuming mirror over y for skipA and skipC
def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.2): self.outlinealpha=outlinealpha self.nint=1.*nintervals self.delta=1./self.nint self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.offset=offset #self.ax.set_xlim(-.1, 2.6) #self.ax.set_ylim(-.1, 3.**.5/2+.1) self.ax.set_ylim(-.1-3.**.5/4., .1+3.**.5/4.) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.scalefcn=lambda ntern:(self.nint-ntern)/self.nint shift=0. self.shift_ntern=[] perminds=[0, 1, 2] self.perminds_ntern=[] for ntern in range(int(self.nint)+1): self.shift_ntern+=[shift] shift+=self.delta*1.5+0.5*self.scalefcn(ntern) self.perminds_ntern+=[perminds] #if ntern%2==0: perminds=[perminds[i] for i in [1, 2, 0]] # else: # perminds=[perminds[i] for i in [1, 0, 2]] self.ax.set_xlim(-.1, shift+self.delta*1.5+1.*self.scalefcn(ntern)+.1) self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=self.delta/3.**.5,resolution=6, color=c, **kwargs)) self.outline() if offset is None: self.offset=self.delta
def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.4): self.outlinealpha = outlinealpha self.ternaryplot = TernaryPlot(ax, outline=False) self.ax = ax self.ax.set_xlim(-.1, 2.6) self.ax.set_ylim(-.1, 3.**.5 / 2 + .1) self.cartendpts = numpy.float32([[0, 0], [.5, numpy.sqrt(3.) / 2.], [1, 0]]) self.ellabels = ellabels self.outline() self.nint = 1. * nintervals self.delta = 1. / self.nint self.patch_xyc = lambda x, y, c, **kwargs: self.ax.add_patch( CirclePolygon((x, y), radius=self.delta / 3.**.5, resolution=6, color=c, **kwargs)) if offset is None: self.offset = self.delta self.qindsfortern_skipind = [ [1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2] ] #sets the order of elements assuming mirror over y for skipA and skipC
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 __init__(self, parent=None, ellabels=["A", "B", "C", "D"], buttons=True, numslices=30): super(echemmultiaxesWidget, self).__init__(parent) if numslices == 5: self.maketernaxes = make10ternaxes self.scatter_axes = scatter_10axes elif numslices == 10: self.maketernaxes = make10ternaxes self.scatter_axes = scatter_10axes elif numslices == 20: self.maketernaxes = make20ternaxes self.scatter_axes = scatter_20axes else: self.maketernaxes = make30ternaxes self.scatter_axes = scatter_30axes mainlayout = QVBoxLayout() self.ellabels = ellabels self.plotw = plotwidget(self) self.plotw.fig.clf() self.axl, self.stpl = self.maketernaxes(fig=self.plotw.fig, ellabels=self.ellabels) mainlayout.addWidget(self.plotw) if buttons: self.buttonBox = QDialogButtonBox(self) self.buttonBox.setGeometry(QRect(520, 195, 160, 26)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Ok) QObject.connect(self.buttonBox, SIGNAL("accepted()"), self.accept) mainlayout.addWidget(self.buttonBox) QObject.connect(self.plotw, SIGNAL("genericclickonplot"), self.clickprocess) self.setLayout(mainlayout) self.terncalc = TernaryPlot(111)
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
def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.4): self.outlinealpha=outlinealpha self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.ax.set_xlim(-.1, 2.6) self.ax.set_ylim(-.1, 3.**.5/2+.1) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.outline() self.nint=1.*nintervals self.delta=1./self.nint self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=self.delta/3.**.5,resolution=6, color=c, **kwargs)) if offset is None: self.offset=self.delta self.qindsfortern_skipind=[[1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2]]#sets the order of elements assuming mirror over y for skipA and skipC
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()
class ternaryfaces_shells: def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.2, patchscale=1.): self.outlinealpha=outlinealpha self.nint=1.*nintervals self.delta=1./self.nint self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.ax.set_aspect(1.) #self.ax.set_xlim(-.1, 2.6) #self.ax.set_ylim(-.1, 3.**.5/2+.1) self.ax.set_ylim(-.1-3.**.5/4., .1+3.**.5/4.) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.scalefcn=lambda nshell:(self.nint-4.*nshell)/self.nint shift=0. self.shift_nshell=[] for nshell in range(int(self.nint//4)+1): self.shift_nshell+=[shift] shift+=self.delta*2.+2.*self.scalefcn(nshell) self.ax.set_xlim(-.1, shift+self.delta+1.*self.scalefcn(nshell)) self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=patchscale*self.delta/3.**.5,resolution=6, color=c, **kwargs)) if outlinealpha>0: self.outline() if offset is None: self.offset=self.delta self.qindsfortern_skipind=[[1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2]]#sets the order of elements assuming mirror over y for skipA and skipC def xy_skipind(self, x, y, skipind, nshell): if skipind%2==0: y=-1.*y+3.**.5/2 y-=3.**.5/2/2. y*=self.scalefcn(nshell) x+=([0.5, 1, 1.5, 0.][skipind]) x*=self.scalefcn(nshell) x+=self.shift_nshell[nshell] return x, y def invert_xy_skipind(self, x, y, skipind, nshell): x-=self.shift_nshell[nshell] x/=self.scalefcn(nshell) x-=([0.5, 1, 1.5, 0.][skipind]) y/=self.scalefcn(nshell) y+=3.**.5/2/2. if skipind%2==0: y=-1.*y+3.**.5/2 return x, y def outline(self, **kwargs): for nshell in range(int(self.nint//4)+int(self.nint%4>0)): for skipind in range(4): skipfirstline=skipind!=3 for i, ep in enumerate(self.cartendpts): for ep2 in self.cartendpts[i+1:]: if skipfirstline: skipfirstline=False continue x, y=self.xy_skipind(numpy.array([ep[0], ep2[0]]), numpy.array([ep[1], ep2[1]]), skipind, nshell) self.ax.plot(x, y, 'k-', alpha=self.outlinealpha, **kwargs) def label(self, onlyterns=False, allelements=False, primeelements=False, **kwargs):#takeabs is to avoid a negative sign for ~0 negative compositions for va, xst, y, inds in zip(['top', 'bottom'], [0, .5], [-3.**.5/4.-self.offset, 3.**.5/4.+self.offset], [[0, 2, 0], [1, 3, 1]]): for count, i in enumerate(inds): self.ax.text(xst+count*1., y, self.ellabels[i], ha='center', va=va, **kwargs) if onlyterns: return for nshell in range(1, int(self.nint//4)+int(self.nint%4>0)): for va, xst, y, inds in zip(['top', 'bottom'], [0, .5], [-3.**.5/4.*self.scalefcn(nshell)-self.offset, 3.**.5/4.*self.scalefcn(nshell)+self.offset], [[2, 0], [3, 1]]): for count, i in enumerate(inds): l=self.ellabels[i] if primeelements: l+="$'$"*nshell else: l+=(r'$_{%d}$' %int(round(100*(1.-3*nshell*self.delta)))) x=(xst+(count+1)*1.)*self.scalefcn(nshell)+self.shift_nshell[nshell] if allelements: temp=copy.copy(self.ellabels) temp.pop(i) l+=''.join([el+(r'$_{%d}$' %int(round(100*(nshell*self.delta)))) for el in temp]) self.ax.text(x, y, l, ha='center', va=va, **kwargs) def toCart(self, quatcomps, skipinds=range(4), nshell=0):#binary and ternary lines need to be plotted multiple times so returns set of (inds,x,y) qc=numpy.array(quatcomps) #qc=qc[(qc==0.).sum(axis=1)>0] # x=numpy.empty(len(qc), dtype='float32') # y=numpy.empty(len(qc), dtype='float32') inds_x_y=[] for si in skipinds: inds=numpy.where(qc[:, si]==0.)[0] if len(inds)==0: continue xt, yt=self.ternaryplot.toCart(qc[inds][:, self.qindsfortern_skipind[si]]) x, y=self.xy_skipind(xt, yt, si, nshell) inds_x_y+=[(inds, x, y)] return inds_x_y def scatter(self, quatcomps, c, skipinds=range(4), s='patch', **kwargs): if s=='patch': patchfcn=lambda x, y, c:self.patch_xyc(x, y, c, **kwargs) else: patchfcn=None quatcomps=numpy.int32(numpy.round(quatcomps*self.nint)) for nshell in range(int(self.nint//4)+int(self.nint%4>0)): ba=((quatcomps==nshell).sum(axis=1, dtype='int32')>0)&((quatcomps>=nshell).prod(axis=1, dtype='int32')>0) self.shellcomps=quatcomps[ba] shellc=c[ba] self.shellcomps=(self.shellcomps-nshell)/(self.nint-4.*nshell) inds_x_y=self.toCart(self.shellcomps, skipinds=skipinds, nshell=nshell) for inds, x, y in inds_x_y: if patchfcn is None: self.ax.scatter(x, y, c=shellc[inds], s=s, **kwargs) else: map(patchfcn, x, y, shellc[inds]) if self.nint%4==0: #single point with no frame ba=(quatcomps==self.nint//4).prod(axis=1, dtype='int32')>0 if True in ba: self.shellcomps=quatcomps[ba]#only 1 comp but might be duplicated shellc=c[ba] if patchfcn is None: for cv in shellc: self.ax.scatter(self.shift_nshell[-1], 0, c=cv, s=s, **kwargs) else: [patchfcn(self.shift_nshell[-1], 0, cv) for cv in shellc] def quatscatter(self, quatcomps, c, skipinds=range(4), azim=-60, elev=30, alphaall=.2, alphashell=1., fontsize=14, outline=True, **kwargs): numsubs=int(self.nint//4)+1 quatcomps=numpy.int32(numpy.round(quatcomps*self.nint)) for nshell in range(int(self.nint//4)+int(self.nint%4>0)): ba=((quatcomps==nshell).sum(axis=1, dtype='int32')>0)&((quatcomps>=nshell).prod(axis=1, dtype='int32')>0) shellcomps=quatcomps[ba] shellc=c[ba] q=QuaternaryPlot((1, numsubs, nshell+1), outline=outline) if alphaall>0: q.scatter(quatcomps*1./self.nint,c=c, alpha=alphaall, **kwargs) if alphashell>0: q.scatter(shellcomps*1./self.nint,c=shellc, alpha=alphashell, **kwargs) if fontsize>0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) if self.nint%4==0: #single point with no frame ba=(quatcomps==self.nint//4).prod(axis=1, dtype='int32')>0 if True in ba: shellcomps=quatcomps[ba]#only 1 comp but might be duplicated shellc=c[ba] q=QuaternaryPlot((1, numsubs, numsubs), outline=outline) q.scatter(quatcomps*1./self.nint,c=c, alpha=alphaall, **kwargs) q.scatter(shellcomps*1./self.nint,c=shellc, alpha=alphashell, **kwargs) if fontsize>0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) def quatplot3D(self, quatcomps, c, skipinds=range(4), azim=-60, elev=30, alphaall=.2, alphashell=1., fontsize=14, outline=True, **kwargs): numsubs=int(self.nint//4)+1 quatcomps=numpy.int32(numpy.round(quatcomps*self.nint)) for nshell in range(int(self.nint//4)+int(self.nint%4>0)): ba=((quatcomps==nshell).sum(axis=1, dtype='int32')>0)&((quatcomps>=nshell).prod(axis=1, dtype='int32')>0) shellcomps=quatcomps[ba] shellc=c[ba] q=QuaternaryPlot((1, numsubs, nshell+1), outline=outline) if alphaall>0: q.plot3D(quatcomps*1./self.nint,c, alpha=alphaall, **kwargs) if alphashell>0: q.plot3D(shellcomps*1./self.nint,shellc, alpha=alphashell, **kwargs) if fontsize>0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) if self.nint%4==0: #single point with no frame ba=(quatcomps==self.nint//4).prod(axis=1, dtype='int32')>0 if True in ba: shellcomps=quatcomps[ba]#only 1 comp but might be duplicated shellc=c[ba] q=QuaternaryPlot((1, numsubs, numsubs), outline=outline) q.plot3D(quatcomps*1./self.nint,c, alpha=alphaall, **kwargs) q.plot3D(shellcomps*1./self.nint,shellc, alpha=alphashell, **kwargs) if fontsize>0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) def toComp(self, x, y, skipinds=range(4)):#takes a single x,y coord from the axes and gets the tirangle by trial and error and converts to a,b,c,d/ skipinds must be the same as that used in .scatter() c=numpy.zeros(4, dtype='float64') for nshell in range(int(self.nint//4)+int(self.nint%4>0)): for si in skipinds: xi, yi=self.invert_xy_skipind(x, y, si, nshell) abc=self.ternaryplot.toComp([[xi, yi]]) if numpy.all((abc>=0.)&(abc<=1.)): c[self.qindsfortern_skipind[si]]=numpy.round((abc*(self.nint-4.*nshell)+nshell)) c[si]=nshell c*=self.delta return c if self.nint%4==0:#if there is an equi-atomic single point outside the triangles, then count it as clicked if outside triagnels with x bigger than middle of the last triangle, xcrit, garb=self.xy_skipind(.5,0,si, nshell)#in the last ternay plot take the x mid-point. y value deosnt' matter if x>xcrit: return numpy.ones(4, dtype='float64')/4. return None
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 #
x=numpy.float32([1,2,4,7,10,13,2,5,8,11,14,3,6,9,1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,4,12,15,4,7,10,13,2,5,8,11,14,2,3,6,4,4,4,4,5,5,5,5,5,6,6,6,6,7,7,7,9,12,1,3,7,10,13,2,4,8,11,1,5,9,7,7,8,8,8,8,9,9,9,9,10,10,10,10,10,11,12,1,4,7,10,2,4,8,3,6,4,7,2,11,11,11,12,12,12,13,13,13,13,14,14,14,15,1,-1,-4,-8,-10,-13,-2,-5,-8,-11,-14,-3,-6,-9,-12,-15,-1,-3,-6,-9,-12,-15,-1,-4,-7,-10,-13,-2,-5,-8,-11,-4,-7,-10,-13,-2,-5,-8,-11,-14,-3,-6,-9,-12,-1,-4,-7,-14,-3,-6,-9,-12,-1,-4,-7,-10,-13,-2,-5,-8,-11,-10,-13,-2,-5,-8,-11,-3,-6,-9,-12,-1,-4,-7,-10,-13,-2,-14,-3,-6,-9,-12,-1,-4,-7,-10,-2,-5,-8,-11,-3,-5,-8,-11,-3,-6,-9,-1,-4,-7,-10,-2,-5,-8,-3,-6,-1,-6,-9,-1,-4,-7,-10,-2,-5,-8,-3,-6,-1]) y=numpy.float32([1,1,1,1,1,1,2,2,2,2,2,3,3,3,-1,-4,-7,-10,-13,-2,-5,-8,-11,-14,-3,-6,-9,-12,-15,-1,3,3,4,4,4,4,5,5,5,5,5,6,6,6,-4,-7,-10,-13,-2,-5,-8,-11,-14,-3,-6,-9,-12,-1,-4,-7,6,6,7,7,7,7,7,8,8,8,8,9,9,9,-10,-13,-2,-5,-8,-11,-3,-6,-9,-12,-1,-4,-7,-10,-13,-2,9,10,10,10,10,11,11,11,12,12,13,13,14,-5,-8,-11,-3,-6,-9,-1,-4,-7,-10,-2,-5,-8,-3,-16,-1,-1,-1,-1,-1,-2,-2,-2,-2,-2,-3,-3,-3,-3,-3,-4,1,1,1,1,1,2,2,2,2,2,3,3,3,3,-4,-4,-4,-4,-5,-5,-5,-5,-5,-6,-6,-6,-6,-7,-7,-7,3,4,4,4,4,5,5,5,5,5,6,6,6,6,-7,-7,-8,-8,-8,-8,-9,-9,-9,-9,-10,-10,-10,-10,-10,-11,6,7,7,7,7,8,8,8,8,9,9,9,9,10,-11,-11,-11,-12,-12,-12,-13,-13,-13,-13,-14,-14,-14,-15,-15,-16,10,10,11,11,11,11,12,12,12,13,13,14]) au=numpy.float32([64.6,64.7,68.6,73,76.1,77.3,65.5,70.5,73.8,78.3,79.2,68.1,72,75.5,65.4,63.8,63.7,62.2,59.7,65.9,65.8,63.7,62,60.7,66.4,65.7,64,63,62.4,69.9,78.2,80.9,68.7,72.7,76.3,79.6,65.7,70.2,74.7,77.3,79.3,64.5,67.8,69.9,66.4,66.7,64.3,64,69.8,69.1,67.3,66.3,62.5,70.7,68.8,68.1,66.4,72.9,70.8,69.8,74.3,77.1,63.4,65.6,74.7,76.5,79,64.8,66.2,71.6,77.8,61.6,66.4,72.4,68.8,65.8,72.3,72.7,71.2,69.8,74,72.9,70.5,69.8,74,75.5,72.1,71.3,69.4,75.3,76.4,59.9,66,71.8,73.7,63,63.2,72,62.7,68.1,62.5,65.3,58.5,75.6,72.7,71.9,76.8,75.2,73.8,77.2,77.2,74.8,74.1,77.2,79.3,75.7,77.9,57.8,63.6,58.4,53.3,51.5,48.5,61.9,56.6,53.5,50.9,47.1,60.7,55.6,52.1,49.5,47,63,62.2,58.4,54.7,51.2,48.9,65.5,61.2,57.1,53.2,50.2,63.7,59.3,55.3,52.3,58.4,53.7,51.3,47.7,60.5,57.3,53.9,49.3,46.8,59.6,56.2,52.5,49,62.3,57.7,54,48.8,62,57.7,53.9,50.7,65.5,59.7,55.4,52,49.5,62.6,57.3,53.8,50.3,51,47.4,59.6,56.5,52.6,48.9,58.3,54.8,51.3,47.9,60.4,56,52.7,50.2,46.8,59.1,48,59.9,55.8,52.4,48.8,62.5,58,55,51.4,60.4,56,52.6,49.2,58.1,54.5,51.5,49.7,56.7,52.5,49.7,58.6,55.4,50.7,47.7,56.7,52,49.8,54.8,51.5,57.2,54.5,50.5,60.1,56.7,52.6,48.3,58.2,54.6,50.6,55.8,52,53.2]) cu=numpy.float32([19.2,16.9,17.2,13.8,12.3,12.1,17.8,14.6,13.8,10.8,11.6,15.6,13.3,11.8,18.9,22.3,23.3,26.3,29.6,18.9,19.5,24.5,27.5,30.8,20.8,22.2,26,28,28.2,16.8,11.7,10,14.5,12.5,11.8,9.9,14.7,13.5,12.1,11.2,10.5,14.5,12.6,13.7,20.6,20.7,25.5,27.7,15.9,19.5,22.2,24.1,28.6,16.4,20.1,21.9,24.3,14.3,18.3,20.3,12,10.7,13.6,14.4,10.5,10,8.3,11.8,12.5,11.4,8.6,13.4,12.6,10.2,21.6,26.1,16,15.8,18.9,22.1,15,16.7,21.1,21.9,13.3,14.7,18.7,20.2,24,15.4,9,13.1,11.1,9.9,9.7,10.6,11.9,9.1,10.3,10,10.4,10.4,10.6,14.8,17.3,20.1,13.1,16.2,17.9,11.9,14.4,16.7,17.6,13.7,12,17,13.6,34.5,19.4,22.2,25.1,25.3,26.8,21.1,24.2,25.8,26.5,29,22.8,25.1,26.7,28.6,29.9,22.5,18.1,18.7,20,21.3,22.1,16.2,17.3,18.2,19.9,20.5,16.1,17,18,18.6,25,27.1,28.8,31.4,25.1,26.4,27.7,30.7,32.9,26,28.3,30.5,32.1,25.5,28.1,30.1,20,15.1,16.5,17.6,18.6,14.6,15.4,16.4,17.6,17.9,13.6,16.1,16.7,17.9,32.3,35.3,27.5,29.4,32.1,34.8,29,30.8,34.3,36.6,27.7,31.2,33.3,35.1,37.6,29.2,18.1,14.5,14.8,16,17.7,13.2,13.9,13.9,15,13.3,14.2,15.2,15.1,12.8,32.5,34,36,32,35,38.1,31.7,33.6,37.6,40.2,33.6,37.4,38.5,35.4,37,33.4,13.7,15.1,11.7,13.4,13.5,15.4,11.3,12.1,13.6,13.1,12.4,12]) si=numpy.float32([16.2,18.4,14.2,13.2,11.7,10.6,16.7,14.9,12.4,10.9,9.2,16.3,14.7,12.7,15.7,13.9,12.9,11.5,10.7,15.2,14.7,11.9,10.5,8.4,12.8,12.1,10,9,9.3,13.3,10.1,9.1,16.8,14.7,11.9,10.5,19.7,16.3,13.2,11.5,10.2,21,19.6,16.4,13,12.6,10.2,8.3,14.3,11.4,10.5,9.5,8.9,12.9,11.1,10,9.3,12.9,11,9.9,13.7,12.2,23,21,14.8,13.5,12.7,23.4,21.3,17,13.6,25,21,17.4,9.5,8.1,11.7,11.4,9.9,8.2,11,10.4,8.4,8.3,12.7,9.8,9.2,8.5,6.6,9.3,14.6,26.9,22.9,18.3,16.6,26.5,24.8,18.8,27,23.9,27.2,24.3,30.9,9.6,10,8,10.1,8.6,8.3,10.9,8.4,8.5,8.2,9.1,8.7,7.3,8.5,7.7,16.9,19.3,21.5,23.2,24.7,17,19.2,20.7,22.6,23.9,16.6,19.2,21.2,21.9,23.1,14.6,19.7,22.9,25.3,27.5,29,18.3,21.5,24.7,26.9,29.3,20.3,23.7,26.7,29.1,16.6,19.1,19.9,20.8,14.4,16.4,18.4,20,20.3,14.4,15.5,17,18.9,12.2,14.2,15.9,31.2,22.9,25.8,28.5,30.7,19.9,24.9,28.2,30.4,32.6,23.8,26.6,29.5,31.8,16.7,17.3,12.9,14.1,15.3,16.3,12.8,14.3,14.4,15.6,11.8,12.9,14,14.7,15.5,11.7,33.9,25.6,29.4,31.6,33.5,24.3,28.1,31.1,33.6,26.3,29.8,32.2,35.6,29.1,12.9,13.9,14.3,11.3,12.5,12.2,9.7,11,11.7,12.2,9.7,10.5,11.6,9.7,11.5,9.3,31.8,34.4,28.2,29.9,33.9,36.3,30.5,33.3,35.8,31.2,35.6,34.9]) 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, color='g', ha='center', va='top') pylab.text(-0.5*rlab, 0.5*3.**.5*rlab, 'Si', fontsize=12, color='b', ha='center', va='top')
# break #data=[(cell, xv, yv, zv, 0., cv) for cell, xva, yva, zva, cv in zip(range(1,26),x, y, z, comp) for xv, yv, zv in zip(xva, yva, zva)] #cells=numpy.array(map(operator.itemgetter(0), data)) #xplot=numpy.array(map(operator.itemgetter(1), data)) #yplot=numpy.array(map(operator.itemgetter(2), data)) #garb=numpy.array(map(operator.itemgetter(3), data)) #garb=numpy.array(map(operator.itemgetter(4), data)) #ca=numpy.array(map(operator.itemgetter(5), data)) #xlab='heat rate (K/s)' #ylab='Tg weighted mean (K)' ##**** #start common plotting routine pylab.figure(figsize=(10, 6)) ax=pylab.subplot(111) stp = TernaryPlot(ax, ellabels=['Au', 'Si', 'Cu']) minlist=[c.min() for c in ca.T] rangelist=numpy.float32([[m, 1.-numpy.concatenate([minlist[:i], minlist[i+1:]]).sum()] for i, m in enumerate(minlist)]) colors=stp.color_comp_calc(ca, rangelist=rangelist) pylab.clf() for cell in set(cells): i=numpy.where(cells==cell) x_cell=numpy.array(xplot[i]) y_cell=numpy.array(yplot[i]) sortarr=numpy.argsort(x_cell) x_cell=x_cell[sortarr] y_cell=y_cell[sortarr] col=colors[i][0]#should all be the same color so take the 1st pylab.plot(x_cell, y_cell, '.', color=col, markersize=16) # for xx, yy in zip(x_cell, y_cell):
def interwithinsegs(p0, p1, p2, p3): x0, y0 = p0 x1, y1 = p1 x2, y2 = p2 x3, y3 = p3 d = (x0 - x1) * (y2 - y3) - (y0 - y1) * (x2 - x3) x = ((x2 - x3) * (x0 * y1 - y0 * x1) - (x0 - x1) * (x2 * y3 - y2 * x3)) / d y = ((y2 - y3) * (x0 * y1 - y0 * x1) - (y0 - y1) * (x2 * y3 - y2 * x3)) / d betweentest = lambda a, b, c: (a >= min(b, c)) and (a <= max(b, c)) return numpy.array([x, y]), betweentest(x, x0, x1) and betweentest( x, x2, x3) and betweentest(y, y0, y1) and betweentest(y, y2, y3) q = TernaryPlot(111) #define these to be modified for each end member z = numpy.zeros(3, dtype='float64') ctr2 = numpy.ones(3, dtype='float64') / 2. endmembers = [] lineendpairs = [] #iterate over 4 end members and draw a line from there to center of opposing face, e.g. (0,.33,.33,.33) for i in range(3): a = copy.copy(z) a[i] = 1. b = copy.copy(ctr2) b[i] = 0. q.line(a, b, fmt='b-') q.scatter([b], c='b', s=15) endmembers += [a]
def interwithinsegs(p0, p1, p2, p3): x0, y0=p0 x1, y1=p1 x2, y2=p2 x3, y3=p3 d=(x0-x1)*(y2-y3)-(y0-y1)*(x2-x3); x=((x2-x3)*(x0*y1-y0*x1)-(x0-x1)*(x2*y3-y2*x3))/d y=((y2-y3)*(x0*y1-y0*x1)-(y0-y1)*(x2*y3-y2*x3))/d betweentest=lambda a, b, c: (a>=min(b, c)) and (a<=max(b, c)) return numpy.array([x, y]), betweentest(x, x0, x1) and betweentest(x, x2, x3) and betweentest(y, y0, y1) and betweentest(y, y2, y3) q=TernaryPlot(111) #define these to be modified for each end member z=numpy.zeros(3, dtype='float64') ctr2=numpy.ones(3, dtype='float64')/2. endmembers=[] lineendpairs=[] #iterate over 4 end members and draw a line from there to center of opposing face, e.g. (0,.33,.33,.33) for i in range(3): a=copy.copy(z) a[i]=1. b=copy.copy(ctr2) b[i]=0. q.line(a, b, fmt='b-') q.scatter([b], c='b', s=15)
f=open(newpath, mode='w') f.write('\n'.join(writelines)) f.close() sys.path.append('C:/Users/Gregoire/Documents/PythonCode/ternaryplot') from myquaternaryutility import QuaternaryPlot from myternaryutility import TernaryPlot for d in dlist: c=numpy.array([d[el] for el in ['A', 'B', 'C', 'D']]) if c.sum()>0: c/=c.sum() d['compositions']=c carr=numpy.array([d['compositions'] for d in dlist]) stpq=QuaternaryPlot(111) stpq.scatter(carr) pylab.figure() for count, tv in enumerate(comps_d): stpq=TernaryPlot((4, 2, count+1)) tvnorm=[tvv/tvv.sum() for tvv in tv] stpq.scatter(tvnorm, marker='.', c='r', edgecolor='none') if count<5: ttt=tc else: ttt=tc19 stpq.scatter(ttt, marker='.', c='g', edgecolor='none') pylab.show()
break if len(ctemp)>0: x_cell+=[xtemp] y_cell+=[ytemp] z_cell+=[ztemp] c_cell+=[ctemp] cell_cell+=[celltemp] c=numpy.array(c) y=numpy.array(y) x=numpy.array(x) z=numpy.array(z) pylab.figure(figsize=(10, 6)) ax=pylab.subplot(111) stp = TernaryPlot(ax, ellabels=['Au', 'Si', 'Cu']) celllist=[1, 2]+range(4, 21)+[22]+[24, 25] minlist=[c.min() for c in comp[numpy.array(celllist)-1, :].T] rangelist=numpy.float32([[m, 1.-numpy.concatenate([minlist[:i], minlist[i+1:]]).sum()] for i, m in enumerate(minlist)]) colors=stp.color_comp_calc(comp[numpy.array(celllist)-1, :], rangelist=rangelist) pylab.clf() for cell, xv, yv, zv in zip(cell_cell, x_cell, y_cell, z_cell): xv=numpy.array(xv) yv=numpy.array(yv) zv=numpy.array(zv) sortarr=numpy.argsort(xv) #pylab.plot(xv[sortarr], yv[sortarr], '.', color=colors[celllist.index(cell)], markersize=16) #pylab.plot(xv[sortarr], yv[sortarr], '-', color=colors[celllist.index(cell)], linewidth=1, alpha=.5) a=yv[sortarr]
class ternaryfaces: def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.4): self.outlinealpha = outlinealpha self.ternaryplot = TernaryPlot(ax, outline=False) self.ax = ax self.ax.set_xlim(-.1, 2.6) self.ax.set_ylim(-.1, 3.**.5 / 2 + .1) self.cartendpts = numpy.float32([[0, 0], [.5, numpy.sqrt(3.) / 2.], [1, 0]]) self.ellabels = ellabels self.outline() self.nint = 1. * nintervals self.delta = 1. / self.nint self.patch_xyc = lambda x, y, c, **kwargs: self.ax.add_patch( CirclePolygon((x, y), radius=self.delta / 3.**.5, resolution=6, color=c, **kwargs)) if offset is None: self.offset = self.delta self.qindsfortern_skipind = [ [1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2] ] #sets the order of elements assuming mirror over y for skipA and skipC def xy_skipind(self, x, y, skipind): x += ([0.5, 1, 1.5, 0.][skipind]) if skipind % 2 == 0: y = -1. * y + 3.**.5 / 2 return x, y def invert_xy_skipind(self, x, y, skipind): x -= ([0.5, 1, 1.5, 0.][skipind]) if skipind % 2 == 0: y = -1. * y + 3.**.5 / 2 return x, y def outline(self): for skipind in range(4): skipfirstline = skipind != 3 for i, ep in enumerate(self.cartendpts): for ep2 in self.cartendpts[i + 1:]: if skipfirstline: skipfirstline = False continue x, y = self.xy_skipind(numpy.array([ep[0], ep2[0]]), numpy.array([ep[1], ep2[1]]), skipind) self.ax.plot(x, y, 'k-', alpha=self.outlinealpha) def label( self, **kwargs ): #takeabs is to avoid a negative sign for ~0 negative compositions for va, xst, y, inds in zip(['top', 'bottom'], [0, .5], [-self.offset, 3.**.5 / 2 + self.offset], [[0, 2, 0], [1, 3, 1]]): for count, i in enumerate(inds): self.ax.text(xst + count * 1., y, self.ellabels[i], ha='center', va=va, **kwargs) def toCart( self, quatcomps, skipinds=range(4) ): #binary and ternary lines need to be plotted multiple times so returns set of (inds,x,y) qc = numpy.array(quatcomps) #qc=qc[(qc==0.).sum(axis=1)>0] # x=numpy.empty(len(qc), dtype='float32') # y=numpy.empty(len(qc), dtype='float32') inds_x_y = [] for si in skipinds: inds = numpy.where(qc[:, si] == 0.)[0] if len(inds) == 0: continue xt, yt = self.ternaryplot.toCart( qc[inds][:, self.qindsfortern_skipind[si]]) x, y = self.xy_skipind(xt, yt, si) inds_x_y += [(inds, x, y)] return inds_x_y def scatter(self, quatcomps, c, skipinds=range(4), s='patch', **kwargs): if s == 'patch': patchfcn = lambda x, y, c: self.patch_xyc(x, y, c, **kwargs) else: patchfcn = None inds_x_y = self.toCart(quatcomps, skipinds=skipinds) for inds, x, y in inds_x_y: if patchfcn is None: self.ax.scatter(x, y, c=c[inds], s=s, **kwargs) else: map(patchfcn, x, y, c[inds]) def toComp( self, x, y, skipinds=range(4) ): #takes a single x,y coord from the axes and gets the tirangle by trial and error and converts to a,b,c,d/ skipinds must be the same as that used in .scatter() c = numpy.zeros(4, dtype='float64') for si in skipinds: xi, yi = self.invert_xy_skipind(x, y, si) abc = self.ternaryplot.toComp([[xi, yi]]) if numpy.all((abc >= 0.) & (abc <= 1.)): c[self.qindsfortern_skipind[si]] = abc return c return None
class ternaryfaces_shells: def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.2, patchscale=1.): self.outlinealpha = outlinealpha self.nint = 1. * nintervals self.delta = 1. / self.nint self.ternaryplot = TernaryPlot(ax, outline=False) self.ax = ax self.ax.set_aspect(1.) #self.ax.set_xlim(-.1, 2.6) #self.ax.set_ylim(-.1, 3.**.5/2+.1) self.ax.set_ylim(-.1 - 3.**.5 / 4., .1 + 3.**.5 / 4.) self.cartendpts = numpy.float32([[0, 0], [.5, numpy.sqrt(3.) / 2.], [1, 0]]) self.ellabels = ellabels self.scalefcn = lambda nshell: (self.nint - 4. * nshell) / self.nint shift = 0. self.shift_nshell = [] for nshell in range(int(self.nint // 4) + 1): self.shift_nshell += [shift] shift += self.delta * 2. + 2. * self.scalefcn(nshell) self.ax.set_xlim(-.1, shift + self.delta + 1. * self.scalefcn(nshell)) #self.fig, self.axis = plt.subplot(nrows=nrows, ncols=ncols, sharex=True, sharey=True) #self.nrows = nrows #self.ncols = ncols self.point_list = [] self.patch_xyc = lambda x, y, c, **kwargs: self.ax.add_patch( CirclePolygon((x, y), radius=patchscale * self.delta / 3.**.5, resolution=6, color=c, **kwargs)) if outlinealpha > 0: self.outline() if offset is None: self.offset = self.delta self.qindsfortern_skipind = [ [1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2] ] #sets the order of elements assuming mirror over y for skipA and skipC # def xy_skipind(self, x, y, skipind, nshell): if skipind % 2 == 0: y = -1. * y + 3.**.5 / 2 y -= 3.**.5 / 2 / 2. y *= self.scalefcn(nshell) x += ([0.5, 1, 1.5, 0.][skipind]) x *= self.scalefcn(nshell) x += self.shift_nshell[nshell] return x, y def invert_xy_skipind(self, x, y, skipind, nshell): x -= self.shift_nshell[nshell] x /= self.scalefcn(nshell) x -= ([0.5, 1, 1.5, 0.][skipind]) y /= self.scalefcn(nshell) y += 3.**.5 / 2 / 2. if skipind % 2 == 0: y = -1. * y + 3.**.5 / 2 return x, y def outline(self, **kwargs): for nshell in range(int(self.nint // 4) + int(self.nint % 4 > 0)): for skipind in range(4): skipfirstline = skipind != 3 for i, ep in enumerate(self.cartendpts): for ep2 in self.cartendpts[i + 1:]: if skipfirstline: skipfirstline = False continue x, y = self.xy_skipind(numpy.array([ep[0], ep2[0]]), numpy.array([ep[1], ep2[1]]), skipind, nshell) self.ax.plot(x, y, 'k-', alpha=self.outlinealpha, **kwargs) def label( self, onlyterns=False, allelements=False, primeelements=False, **kwargs ): #takeabs is to avoid a negative sign for ~0 negative compositions for va, xst, y, inds in zip( ['top', 'bottom'], [0, .5], [-3.**.5 / 4. - self.offset, 3.**.5 / 4. + self.offset], [[0, 2, 0], [1, 3, 1]]): for count, i in enumerate(inds): self.ax.text(xst + count * 1., y, self.ellabels[i], ha='center', va=va, **kwargs) if onlyterns: return for nshell in range(1, int(self.nint // 4) + int(self.nint % 4 > 0)): for va, xst, y, inds in zip(['top', 'bottom'], [0, .5], [ -3.**.5 / 4. * self.scalefcn(nshell) - self.offset, 3.**.5 / 4. * self.scalefcn(nshell) + self.offset ], [[2, 0], [3, 1]]): for count, i in enumerate(inds): l = self.ellabels[i] if primeelements: l += "$'$" * nshell else: l += (r'$_{%d}$' % int(round(100 * (1. - 3 * nshell * self.delta)))) x = (xst + (count + 1) * 1. ) * self.scalefcn(nshell) + self.shift_nshell[nshell] if allelements: temp = copy.copy(self.ellabels) temp.pop(i) l += ''.join([ el + (r'$_{%d}$' % int(round(100 * (nshell * self.delta)))) for el in temp ]) self.ax.text(x, y, l, ha='center', va=va, **kwargs) def toCart( self, quatcomps, skipinds=range(4), nshell=0 ): #binary and ternary lines need to be plotted multiple times so returns set of (inds,x,y) qc = numpy.array(quatcomps) #qc=qc[(qc==0.).sum(axis=1)>0] # x=numpy.empty(len(qc), dtype='float32') # y=numpy.empty(len(qc), dtype='float32') inds_x_y = [] for si in skipinds: inds = numpy.where(qc[:, si] == 0.)[0] if len(inds) == 0: continue xt, yt = self.ternaryplot.toCart( qc[inds][:, self.qindsfortern_skipind[si]]) x, y = self.xy_skipind(xt, yt, si, nshell) inds_x_y += [(inds, x, y)] return inds_x_y def scatter(self, quatcomps, c, skipinds=range(4), s='patch', **kwargs): if s == 'patch': patchfcn = lambda x, y, c: self.patch_xyc(x, y, c, **kwargs) else: patchfcn = None quatcomps = numpy.int32(numpy.round(quatcomps * self.nint)) for nshell in range(int(self.nint // 4) + int(self.nint % 4 > 0)): ba = ((quatcomps == nshell).sum(axis=1, dtype='int32') > 0) & ( (quatcomps >= nshell).prod(axis=1, dtype='int32') > 0) self.shellcomps = quatcomps[ba] shellc = c[ba] self.shellcomps = (self.shellcomps - nshell) / (self.nint - 4. * nshell) inds_x_y = self.toCart(self.shellcomps, skipinds=skipinds, nshell=nshell) for inds, x, y in inds_x_y: if patchfcn is None: #self.ax.scatter(x, y, c=shellc[inds], s=s, **kwargs) self.point_list.append( self.ax.scatter(x, y, c=shellc[inds], s=s, picker=True, **kwargs)) else: map(patchfcn, x, y, shellc[inds]) if self.nint % 4 == 0: #single point with no frame ba = (quatcomps == self.nint // 4).prod(axis=1, dtype='int32') > 0 if True in ba: self.shellcomps = quatcomps[ ba] #only 1 comp but might be duplicated shellc = c[ba] if patchfcn is None: for cv in shellc: #self.ax.scatter(self.shift_nshell[-1], 0, c=cv, s=s, **kwargs) self.point_list.append( self.ax.scatter(self.shift_nshell[-1], 0, c=cv, s=s, picker=True, **kwargs)) else: [patchfcn(self.shift_nshell[-1], 0, cv) for cv in shellc] #Returns a list with all the points in the scatterplot return self.point_list def quatscatter(self, quatcomps, c, skipinds=range(4), azim=-60, elev=30, alphaall=.2, alphashell=1., fontsize=14, outline=True, **kwargs): numsubs = int(self.nint // 4) + 1 quatcomps = numpy.int32(numpy.round(quatcomps * self.nint)) for nshell in range(int(self.nint // 4) + int(self.nint % 4 > 0)): ba = ((quatcomps == nshell).sum(axis=1, dtype='int32') > 0) & ( (quatcomps >= nshell).prod(axis=1, dtype='int32') > 0) shellcomps = quatcomps[ba] shellc = c[ba] q = QuaternaryPlot((1, numsubs, nshell + 1), outline=outline) if alphaall > 0: q.scatter(quatcomps * 1. / self.nint, c=c, alpha=alphaall, **kwargs) if alphashell > 0: q.scatter(shellcomps * 1. / self.nint, c=shellc, alpha=alphashell, **kwargs) if fontsize > 0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) if self.nint % 4 == 0: #single point with no frame ba = (quatcomps == self.nint // 4).prod(axis=1, dtype='int32') > 0 if True in ba: shellcomps = quatcomps[ ba] #only 1 comp but might be duplicated shellc = c[ba] q = QuaternaryPlot((1, numsubs, numsubs), outline=outline) q.scatter(quatcomps * 1. / self.nint, c=c, alpha=alphaall, **kwargs) q.scatter(shellcomps * 1. / self.nint, c=shellc, alpha=alphashell, **kwargs) if fontsize > 0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) def quatplot3D(self, quatcomps, c, skipinds=range(4), azim=-60, elev=30, alphaall=.2, alphashell=1., fontsize=14, outline=True, **kwargs): numsubs = int(self.nint // 4) + 1 quatcomps = numpy.int32(numpy.round(quatcomps * self.nint)) for nshell in range(int(self.nint // 4) + int(self.nint % 4 > 0)): ba = ((quatcomps == nshell).sum(axis=1, dtype='int32') > 0) & ( (quatcomps >= nshell).prod(axis=1, dtype='int32') > 0) shellcomps = quatcomps[ba] shellc = c[ba] q = QuaternaryPlot((1, numsubs, nshell + 1), outline=outline) if alphaall > 0: q.plot3D(quatcomps * 1. / self.nint, c, alpha=alphaall, **kwargs) if alphashell > 0: q.plot3D(shellcomps * 1. / self.nint, shellc, alpha=alphashell, **kwargs) if fontsize > 0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) if self.nint % 4 == 0: #single point with no frame ba = (quatcomps == self.nint // 4).prod(axis=1, dtype='int32') > 0 if True in ba: shellcomps = quatcomps[ ba] #only 1 comp but might be duplicated shellc = c[ba] q = QuaternaryPlot((1, numsubs, numsubs), outline=outline) q.plot3D(quatcomps * 1. / self.nint, c, alpha=alphaall, **kwargs) q.plot3D(shellcomps * 1. / self.nint, shellc, alpha=alphashell, **kwargs) if fontsize > 0: q.label(ha='center', va='center', fontsize=fontsize) q.set_projection(azim=azim, elev=elev) def toComp( self, x, y, skipinds=range(4) ): #takes a single x,y coord from the axes and gets the tirangle by trial and error and converts to a,b,c,d/ skipinds must be the same as that used in .scatter() c = numpy.zeros(4, dtype='float64') for nshell in range(int(self.nint // 4) + int(self.nint % 4 > 0)): for si in skipinds: xi, yi = self.invert_xy_skipind(x, y, si, nshell) abc = self.ternaryplot.toComp([[xi, yi]]) if numpy.all((abc >= 0.) & (abc <= 1.)): c[self.qindsfortern_skipind[si]] = numpy.round( (abc * (self.nint - 4. * nshell) + nshell)) c[si] = nshell c *= self.delta return c if self.nint % 4 == 0: #if there is an equi-atomic single point outside the triangles, then count it as clicked if outside triagnels with x bigger than middle of the last triangle, xcrit, garb = self.xy_skipind( .5, 0, si, nshell ) #in the last ternay plot take the x mid-point. y value deosnt' matter if x > xcrit: return numpy.ones(4, dtype='float64') / 4. return None
#data=[(cell, xv,yv, zv, zv[numpy.argmax(yv)], cv) for cell,xv,yv, zv, cv in zip(range(1,26),x,y, z, comp) if len(zv)>0] #Tg avergaed over multiple scans 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:
class ternaryfaces: def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.4): self.outlinealpha=outlinealpha self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.ax.set_xlim(-.1, 2.6) self.ax.set_ylim(-.1, 3.**.5/2+.1) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.outline() self.nint=1.*nintervals self.delta=1./self.nint self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=self.delta/3.**.5,resolution=6, color=c, **kwargs)) if offset is None: self.offset=self.delta self.qindsfortern_skipind=[[1, 2, 3], [2, 3, 0], [3, 0, 1], [0, 1, 2]]#sets the order of elements assuming mirror over y for skipA and skipC def xy_skipind(self, x, y, skipind): x+=([0.5, 1, 1.5, 0.][skipind]) if skipind%2==0: y=-1.*y+3.**.5/2 return x, y def invert_xy_skipind(self, x, y, skipind): x-=([0.5, 1, 1.5, 0.][skipind]) if skipind%2==0: y=-1.*y+3.**.5/2 return x, y def outline(self): for skipind in range(4): skipfirstline=skipind!=3 for i, ep in enumerate(self.cartendpts): for ep2 in self.cartendpts[i+1:]: if skipfirstline: skipfirstline=False continue x, y=self.xy_skipind(numpy.array([ep[0], ep2[0]]), numpy.array([ep[1], ep2[1]]), skipind) self.ax.plot(x, y, 'k-', alpha=self.outlinealpha) def label(self, **kwargs):#takeabs is to avoid a negative sign for ~0 negative compositions for va, xst, y, inds in zip(['top', 'bottom'], [0, .5], [-self.offset, 3.**.5/2+self.offset], [[0, 2, 0], [1, 3, 1]]): for count, i in enumerate(inds): self.ax.text(xst+count*1., y, self.ellabels[i], ha='center', va=va, **kwargs) def toCart(self, quatcomps, skipinds=range(4)):#binary and ternary lines need to be plotted multiple times so returns set of (inds,x,y) qc=numpy.array(quatcomps) #qc=qc[(qc==0.).sum(axis=1)>0] # x=numpy.empty(len(qc), dtype='float32') # y=numpy.empty(len(qc), dtype='float32') inds_x_y=[] for si in skipinds: inds=numpy.where(qc[:, si]==0.)[0] if len(inds)==0: continue xt, yt=self.ternaryplot.toCart(qc[inds][:, self.qindsfortern_skipind[si]]) x, y=self.xy_skipind(xt, yt, si) inds_x_y+=[(inds, x, y)] return inds_x_y def scatter(self, quatcomps, c, skipinds=range(4), s='patch', **kwargs): if s=='patch': patchfcn=lambda x, y, c:self.patch_xyc(x, y, c, **kwargs) else: patchfcn=None inds_x_y=self.toCart(quatcomps, skipinds=skipinds) for inds, x, y in inds_x_y: if patchfcn is None: self.ax.scatter(x, y, c=c[inds], s=s, **kwargs) else: map(patchfcn, x, y, c[inds]) def toComp(self, x, y, skipinds=range(4)):#takes a single x,y coord from the axes and gets the tirangle by trial and error and converts to a,b,c,d/ skipinds must be the same as that used in .scatter() c=numpy.zeros(4, dtype='float64') for si in skipinds: xi, yi=self.invert_xy_skipind(x, y, si) abc=self.ternaryplot.toComp([[xi, yi]]) if numpy.all((abc>=0.)&(abc<=1.)): c[self.qindsfortern_skipind[si]]=abc return c return None
class echemmultiaxesWidget(QDialog): def __init__(self, parent=None, ellabels=["A", "B", "C", "D"], buttons=True, numslices=30): super(echemmultiaxesWidget, self).__init__(parent) if numslices == 5: self.maketernaxes = make10ternaxes self.scatter_axes = scatter_10axes elif numslices == 10: self.maketernaxes = make10ternaxes self.scatter_axes = scatter_10axes elif numslices == 20: self.maketernaxes = make20ternaxes self.scatter_axes = scatter_20axes else: self.maketernaxes = make30ternaxes self.scatter_axes = scatter_30axes mainlayout = QVBoxLayout() self.ellabels = ellabels self.plotw = plotwidget(self) self.plotw.fig.clf() self.axl, self.stpl = self.maketernaxes(fig=self.plotw.fig, ellabels=self.ellabels) mainlayout.addWidget(self.plotw) if buttons: self.buttonBox = QDialogButtonBox(self) self.buttonBox.setGeometry(QRect(520, 195, 160, 26)) self.buttonBox.setOrientation(Qt.Horizontal) self.buttonBox.setStandardButtons(QDialogButtonBox.Ok) QObject.connect(self.buttonBox, SIGNAL("accepted()"), self.accept) mainlayout.addWidget(self.buttonBox) QObject.connect(self.plotw, SIGNAL("genericclickonplot"), self.clickprocess) self.setLayout(mainlayout) self.terncalc = TernaryPlot(111) def plot(self, d, cb=True): if "fomlabel" in d.keys(): cblabel = d["fomlabel"] else: cblabel = "" self.scatter_axes( d["comps"], d["fom"], self.stpl, s=18, edgecolors="none", cb=cb, cblabel=cblabel, cmap=d["cmap"], norm=d["norm"], ) def clearandplot(self, d, cb=True, ellabels=None): if "fomlabel" in d.keys(): cblabel = d["fomlabel"] else: cblabel = "" self.plotw.fig.clf() if not ellabels is None: self.ellabels = ellabels self.axl, self.stpl = self.maketernaxes(fig=self.plotw.fig, ellabels=self.ellabels) self.scatter_axes( d["comps"], d["fom"], self.stpl, s=18, edgecolors="none", cb=cb, cblabel=cblabel, cmap=d["cmap"], norm=d["norm"], ) self.plotw.fig.canvas.draw() def clickprocess(self, coords_button): xc, yc, button = coords_button clickcomplist = self.terncalc.toComp(numpy.array([[xc, yc]])) print "clicked ternary composition is ", clickcomplist[0]
class ternaryfaces_folded: def __init__(self, ax, ellabels=['A', 'B', 'C', 'D'], offset=None, nintervals=10., outlinealpha=0.2): self.outlinealpha=outlinealpha self.nint=1.*nintervals self.delta=1./self.nint self.ternaryplot=TernaryPlot(ax, outline=False) self.ax=ax self.offset=offset #self.ax.set_xlim(-.1, 2.6) #self.ax.set_ylim(-.1, 3.**.5/2+.1) self.ax.set_ylim(-.1-3.**.5/4., .1+3.**.5/4.) self.cartendpts=numpy.float32([[0, 0], [.5, numpy.sqrt(3.)/2.], [1, 0]]) self.ellabels=ellabels self.scalefcn=lambda ntern:(self.nint-ntern)/self.nint shift=0. self.shift_ntern=[] perminds=[0, 1, 2] self.perminds_ntern=[] for ntern in range(int(self.nint)+1): self.shift_ntern+=[shift] shift+=self.delta*1.5+0.5*self.scalefcn(ntern) self.perminds_ntern+=[perminds] #if ntern%2==0: perminds=[perminds[i] for i in [1, 2, 0]] # else: # perminds=[perminds[i] for i in [1, 0, 2]] self.ax.set_xlim(-.1, shift+self.delta*1.5+1.*self.scalefcn(ntern)+.1) self.patch_xyc=lambda x, y, c, **kwargs:self.ax.add_patch(CirclePolygon((x, y),radius=self.delta/3.**.5,resolution=6, color=c, **kwargs)) self.outline() if offset is None: self.offset=self.delta def xy_ntern(self, x, y, ntern): if ntern%2==1: y=-1.*y+3.**.5/2 y-=3.**.5/2/2. y*=self.scalefcn(ntern) x*=self.scalefcn(ntern) x+=self.shift_ntern[ntern] return x, y def invert_xy_ntern(self, x, y, ntern): x-=self.shift_ntern[ntern] x/=self.scalefcn(ntern) y/=self.scalefcn(ntern) y+=3.**.5/2/2. if ntern%2==1: y=-1.*y+3.**.5/2 return x, y def outline(self): for ntern in range(int(self.nint)): for i, ep in enumerate(self.cartendpts): for ep2 in self.cartendpts[i+1:]: x, y=self.xy_ntern(numpy.array([ep[0], ep2[0]]), numpy.array([ep[1], ep2[1]]), ntern) self.ax.plot(x, y, 'k-', alpha=self.outlinealpha) def label(self, **kwargs):#takeabs is to avoid a negative sign for ~0 negative compositions for count, (va, y) in enumerate(zip(['top','bottom'], [-3.**.5/4.-self.offset, 3.**.5/4.+self.offset])): self.ax.text(count*.5, y, self.ellabels[count], ha='center', va=va, **kwargs) for i in range(0, int(self.nint)): y=(3.**.5/4.)*self.scalefcn(i)+self.offset yd=(3.**.5/4.)*self.scalefcn(i)+self.offset*1.5 if i%2==1: va='bottom' vad='top' yd*=-1 else: va='top' y*=-1 vad='bottom' x=self.shift_ntern[i+1]+.5*self.scalefcn(i+1) self.ax.text(x, y, self.ellabels[(i+2)%3], ha='center', va=va, **kwargs) if i==int(self.nint)-1: x+=self.scalefcn(i+1)+self.offset yd=0. vad='center' had='left' else: had='center' self.ax.text(x, yd, self.ellabels[3]+(r'$_{%d}$' %(int(round(100*(i+1)*self.delta)))), ha=had, va=vad, **kwargs) def toCart(self, quatcomps, ntern): qc=numpy.array(quatcomps) perminds=self.perminds_ntern[ntern] x, y=self.ternaryplot.toCart(qc[:, perminds]) x, y=self.xy_ntern(x, y, ntern) return x, y def scatter(self, quatcomps, c, s='patch', **kwargs): if s=='patch': patchfcn=lambda x, y, c:self.patch_xyc(x, y, c, **kwargs) else: patchfcn=None quatcomps=numpy.int32(numpy.round(quatcomps*self.nint)) for ntern in range(int(self.nint)): ba=quatcomps[:, -1]==ntern self.shellcomps=quatcomps[ba] shellc=c[ba] self.shellcomps=self.shellcomps[:, :-1]/(self.nint-ntern) if len(self.shellcomps)==0: continue x, y=self.toCart(self.shellcomps, ntern) if patchfcn is None: self.ax.scatter(x, y, c=shellc, **kwargs) else: map(patchfcn, x, y, shellc) ba=quatcomps[:, -1]==self.nint if True in ba: self.shellcomps=quatcomps[ba]#only 1 comp but might be duplicated shellc=c[ba] if patchfcn is None: for cv in shellc: self.ax.scatter(self.shift_ntern[-1], 0, c=cv, s=s, **kwargs) else: [patchfcn(self.shift_ntern[-1], 0, cv) for cv in shellc] def toComp(self, x, y, skipinds=range(4)):#takes a single x,y coord from the axes and gets the tirangle by trial and error and converts to a,b,c,d/ skipinds must be the same as that used in .scatter() c=numpy.zeros(4, dtype='float64') for ntern in range(int(self.nint)): xi, yi=self.invert_xy_ntern(x, y, ntern) abc=self.ternaryplot.toComp([[xi, yi]]) if numpy.all((abc>=0.)&(abc<=1.)): print ntern c[self.perminds_ntern[ntern]]=abc*(self.nint-ntern) c[-1]=ntern c*=self.delta return c xcrit, garb=self.xy_ntern(.5,0,ntern)#in the last ternay plot take the x mid-point. y value deosnt' matter if x>xcrit: return numpy.float64([0, 0, 0, 1]) return None
13.9, 14.3, 11.3, 12.5, 12.2, 9.7, 11, 11.7, 12.2, 9.7, 10.5, 11.6, 9.7, 11.5, 9.3, 31.8, 34.4, 28.2, 29.9, 33.9, 36.3, 30.5, 33.3, 35.8, 31.2, 35.6, 34.9 ]) 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,