def plotbinarylines_axandinset(ellabels=['A', 'B', 'C', 'D'], fig=None, mainax=[.3, .12, .6, .83], insetax=[0, .7, .2, .3], numcomppts=21, view_azim=-159, view_elev=30, **kwargs): if fig is None: fig = pylab.figure(figsize=(8, 5)) ax = fig.add_axes(mainax) ax2 = fig.add_axes(insetax, projection='3d') stpq = QuaternaryPlot(ax2, ellabels=ellabels) comppairs = [] a = numpy.linspace(0, 1, 21) count = -1 for i in range(4): for j in range(i + 1, 4): count += 1 b = numpy.zeros((numcomppts, 4), dtype='float64') b[:, i] = a b[:, j] = 1. - a comppairs += [(c1, c2) for c1, c2 in zip(b[:-1], b[1:])] for (c1, c2) in comppairs: stpq.line(c1, c2, fmt='-', c=stpq.rgb_comp([(c1 + c2) / 2.])[0], **kwargs) stpq.set_projection(azim=view_azim, elev=view_elev) stpq.label() return ax, ax2
class binarylines: def __init__(self, ax, insetax, ellabels=['A', 'B', 'C', 'D'], offset=0.02, numcomppts=21, view_azim=-159, view_elev=30, **kwargs): self.ax=ax self.insetax=insetax self.ellabels=ellabels self.stpq=QuaternaryPlot(insetax, ellabels=ellabels, offset=offset) comppairs=[] a=numpy.linspace(0, 1, 21) count=-1 for i in range(4): for j in range(i+1, 4): count+=1 b=numpy.zeros((numcomppts, 4), dtype='float64') b[:, i]=a b[:, j]=1.-a comppairs+=[(c1, c2) for c1, c2 in zip(b[:-1], b[1:])] for (c1, c2) in comppairs: self.stpq.line(c1, c2, fmt='-', c=self.stpq.rgb_comp([(c1+c2)/2.])[0], **kwargs) self.stpq.set_projection(azim=view_azim, elev=view_elev) self.stpq.label() def plotbinaryfom(self, comps, fom, **kwargs): cb=comps>.001 ms=['<','>','^','v','s','D'] count=-1 for i in range(4): for j in range(i+1, 4): count+=1 k, l=tuple(set(range(4))-set([i, j])) barr=numpy.array([numpy.logical_not(b[k]|b[l]) for b in cb]) #numpy.logical_xor(b[i], b[j])& if not numpy.any(barr): continue cmps=comps[barr] inds=numpy.argsort(cmps[:, j]) cmps=cmps[inds] cols=self.stpq.rgb_comp(cmps) ys=fom[barr][inds] for count2, (c, col, y) in enumerate(zip(cmps, cols, ys)): if count2==len(ys)//2: self.ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, label='%s,%s' %(self.ellabels[i], self.ellabels[j]), **kwargs) else: self.ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, **kwargs) #self.ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor='None') for count3, (c1, col1, y1, c2, col2, y2) in enumerate(zip(cmps[:-1], cols[:-1], ys[:-1], cmps[1:], cols[1:], ys[1:])): col=numpy.array([col1, col2]).mean(axis=0) self.ax.plot([c1[j], c2[j]], [y1, y2], '-', c=col, **kwargs) def binarylineslegend(self, **kwargs): try: self.ax.legend(**kwargs) except: pass
def plotbinarylines_axandinset(ellabels=['A', 'B', 'C', 'D'], fig=None, mainax=[.3, .12, .6, .83], insetax=[0, .7, .2, .3], numcomppts=21, view_azim=-159, view_elev=30, **kwargs): if fig is None: fig=pylab.figure(figsize=(8, 5)) ax=fig.add_axes(mainax) ax2=fig.add_axes(insetax, projection='3d') stpq=QuaternaryPlot(ax2, ellabels=ellabels) comppairs=[] a=numpy.linspace(0, 1, 21) count=-1 for i in range(4): for j in range(i+1, 4): count+=1 b=numpy.zeros((numcomppts, 4), dtype='float64') b[:, i]=a b[:, j]=1.-a comppairs+=[(c1, c2) for c1, c2 in zip(b[:-1], b[1:])] for (c1, c2) in comppairs: stpq.line(c1, c2, fmt='-', c=stpq.rgb_comp([(c1+c2)/2.])[0], **kwargs) stpq.set_projection(azim=view_azim, elev=view_elev) stpq.label() return ax, ax2
q.scatter(comps, c=comps[:, 3]) q.label(ha="center", va="center", fontsize=16) q.set_projection(azim=-17, elev=-6) inds, distfromplane, xyparr, xyp_verts, intriangle = q2.filterbydistancefromplane( comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=False, returnall=True ) indsnot = q2.filterbydistancefromplane( comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=True ) print len(inds), " points" q2.scatter(comps[inds], c=comps[inds, 3]) q2.scatter(comps[indsnot], c="grey", marker=".", s=5) q2.line(compvert0, compvert1) q2.line(compvert1, compvert2) q2.line(compvert2, compvert0) q2.label(ha="center", va="center", fontsize=16) q2.set_projection(azim=-17, elev=-6) pylab.figure() ax = pylab.subplot(111) q2.plotfominselectedplane( ax, xyparr[inds], comps[inds, -1], xyp_verts=xyp_verts, vertcomps_labels=[compvert0, compvert1, compvert2], s=20 )
q = QuaternaryPlot(111) #define these to be modified for each end member z = numpy.zeros(4, dtype='float64') ctr3 = numpy.ones(4, dtype='float64') / 3. 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(4): a = copy.copy(z) a[i] = 1. b = copy.copy(ctr3) b[i] = 0. q.line(a, b, fmt='b-') q.scatter([b], c='b', s=15) endmembers += [a] lineendpairs += [[a, b]] #convert the end members and pairs of endpts to cartesian xyz_lineendpairs = [numpy.array(q.toCart(ls)).T for ls in lineendpairs] xyz_endmembers = numpy.array(q.toCart(endmembers)).T #choose the composition of a phase and draw the trivial phase field lines phcomp = numpy.array([.1, .3, .2, .4]) q.scatter([phcomp], c='r', s=20) for i in range(4): a = copy.copy(z) a[i] = 1. q.line(a, phcomp, fmt='r-')
invertbool=0 if calctype==0: selectinds, distfromlin, lineparameter=quatx.filterbydistancefromline(compsall[code0inds], compverts[0], compverts[1], critdist, betweenpoints=betweenbool, invlogic=invertbool, returnall=True) lineparameter=lineparameter[selectinds] elif calctype==1: selectinds, distfromplane, xyparr, xyp_verts,intriangle=quatx.filterbydistancefromplane(compsall[code0inds], compverts[0], compverts[1], compverts[2], critdist, withintriangle=betweenbool, invlogic=invertbool, returnall=True) xyparr=xyparr[selectinds] fomselectx=fomall[code0inds][selectinds] compsselectx=compsall[code0inds][selectinds] xsecfig=pylab.figure() xsecax=pylab.subplot(111) if calctype==0: quatx.line(compverts[0], compverts[1]) quatx.plotfomalonglineparameter(xsecax, lineparameter, fomselectx, compend1=compverts[0], compend2=compverts[1], lineparticks=numpy.linspace(0, 1, 4), ls='none', marker='.') elif calctype==1: quatx.plotfominselectedplane(xsecax, xyparr, fomselectx, xyp_verts=xyp_verts, vertcomps_labels=[compverts[0], compverts[1], compverts[2]], s=20, edgecolor='none', cmap=cmap, norm=norm) quatx.line(compverts[0], compverts[1]) quatx.line(compverts[0], compverts[2]) quatx.line(compverts[2], compverts[1]) quatx.scatter(compsselectx, c=fomselectx, s=20, cmap=cmap, norm=norm, edgecolor='none')#vmin=vmin, vmax=vmax, cb=quatxfig.colorbar(quatx.mappable, cax=cbax, extend=extend, cmap=cmap, norm=norm) cb.set_label(fomlabel, fontsize=18) quatx.set_projection(azim=view_azim, elev=view_elev) if SYSTEM==1: axbin.set_ylim(.23, .7) if SYSTEM==6:
pylab.figure() #axq=pylab.subplot(111) stpq=QuaternaryPlot(111, ellabels=ellabels) comps=numpy.array([dropd[elkey] for elkey in elkeys]).T selectinds, distfromlin, lineparameter=stpq.filterbydistancefromline(comps, compverts[0], compverts[1], critdist, betweenpoints=betweenbool, invlogic=invertbool, returnall=True) dropd['lineparameter']=lineparameter dropd['distfromlin']=distfromlin lineparameter=lineparameter[selectinds] cols=stpq.rgb_comp(comps[selectinds]) stpq.plotbycolor(comps[selectinds], cols, marker='o', markersize=5, alpha=.6) stpq.line(compverts[0], compverts[1], lw=2) #stpq.scatter(comps[selectinds], pointsize stpq.set_projection(azim=view_azim, elev=view_elev) stpq.label(fontsize=20) pylab.savefig(os.path.join(savefolder, 'QuatPoints.png')) pylab.figure() for k, v in dropd.iteritems(): # if k in elkeys or k in ellabels or k in ['Sample', 'x(mm)', 'y(mm)', 'compositions']: # continue pylab.clf() ax=pylab.subplot(111) fomselect=v[selectinds] stpq.plotfomalonglineparameter(ax, lineparameter, fomselect, compend1=compverts[0], compend2=compverts[1], lineparticks=numpy.linspace(0, 1, 5), ls='none', marker='.', ticklabelkwargdict=dict([('rotation', -20), ('horizontalalignment', 'left')]))
compvert2, critdist, withintriangle=withintriangle, invlogic=False, returnall=True) indsnot = q2.filterbydistancefromplane(comps, compvert0, compvert1, compvert2, critdist, withintriangle=withintriangle, invlogic=True) print len(inds), ' points' q2.scatter(comps[inds], c=comps[inds, 3]) q2.scatter(comps[indsnot], c='grey', marker='.', s=5) q2.line(compvert0, compvert1) q2.line(compvert1, compvert2) q2.line(compvert2, compvert0) q2.label(ha='center', va='center', fontsize=16) q2.set_projection(azim=-17, elev=-6) pylab.figure() ax = pylab.subplot(111) q2.plotfominselectedplane(ax, xyparr[inds], comps[inds, -1], xyp_verts=xyp_verts, vertcomps_labels=[compvert0, compvert1, compvert2], s=20)
def plot(self): s = 25 self.plotw_tern.axes.cla() self.plotw_quat.axes.cla() self.cbax_quat.cla() self.cbax_tern.cla() fom = self.fom azim = -159.0 elev = 30.0 vstr = str(self.azimelevLineEdit.text()).strip() if "," in vstr: a, b, c = vstr.partition(",") try: a = myeval(a.strip()) c = myeval(c.strip()) self.vmin = a self.vmax = c except: pass if self.revcmapCheckBox.isChecked(): cmap = cm.jet_r else: cmap = cm.jet clip = True skipoutofrange = [False, False] self.vmin = fom.min() self.vmax = fom.max() vstr = str(self.vminmaxLineEdit.text()).strip() if "," in vstr: a, b, c = vstr.partition(",") try: a = myeval(a.strip()) c = myeval(c.strip()) self.vmin = a self.vmax = c for count, (fcn, le) in enumerate( zip([cmap.set_under, cmap.set_over], [self.belowrangecolLineEdit, self.aboverangecolLineEdit]) ): vstr = str(le.text()).strip() vstr = vstr.replace('"', "").replace("'", "") print "^^^", vstr, "none" in vstr or "None" in vstr if "none" in vstr or "None" in vstr: skipoutofrange[count] = True continue if len(vstr) == 0: continue c = col_string(vstr) try: fcn(c) clip = False except: print "color entry not understood:", vstr except: pass print "4" norm = colors.Normalize(vmin=self.vmin, vmax=self.vmax, clip=clip) print "fom min, max, mean, std:", fom.min(), fom.max(), fom.mean(), fom.std() comps = self.comps # comment out this skipoutofrange becuase it could mess up the indexing # print 'skipoutofrange', skipoutofrange # print len(fom) # if skipoutofrange[0]: # inds=numpy.where(fom>=self.vmin) # fom=fom[inds] # comps=comps[inds] # print len(fom) # if skipoutofrange[1]: # inds=numpy.where(fom<=self.vmax) # fom=fom[inds] # comps=comps[inds] # print len(fom) if numpy.any(fom > self.vmax): if numpy.any(fom < self.vmin): extend = "both" else: extend = "max" elif numpy.any(fom < self.vmin): extend = "min" else: extend = "neither" print "extend ", extend i = self.ternskipComboBox.currentIndex() inds = [j for j in range(4) if j != i][:3] terncomps = numpy.array([c[inds] / c[inds].sum() for c in comps]) reordercomps = comps[:, inds + [i]] reorderlabels = [self.ellabels[j] for j in inds + [i]] fomselect = fom[self.selectinds] compsselect = comps[self.selectinds] reordercompsselect = reordercomps[self.selectinds] fomlabel = self.dataclass.fomlabel self.stackedternplotdict = dict( [ ("comps", reordercomps), ("fom", fom), ("cmap", cmap), ("norm", norm), ("ellabels", reorderlabels), ("fomlabel", fomlabel), ("extend", extend), ] ) self.echem30_all.clearandplot(self.stackedternplotdict, cb=True, ellabels=reorderlabels) print len(fomselect), " samples selected" if len(fomselect) > 0: self.stackedternplotdictselect = dict( [ ("comps", reordercompsselect), ("fom", fomselect), ("cmap", cmap), ("norm", norm), ("ellabels", reorderlabels), ("fomlabel", fomlabel), ("extend", extend), ] ) self.echem30_select.clearandplot(self.stackedternplotdictselect, cb=True, ellabels=reorderlabels) quat = QuaternaryPlot(self.plotw_quat.axes, ellabels=self.ellabels, offset=0) quat.label() quat.scatter( compsselect, c=fomselect, s=s, cmap=cmap, norm=norm, edgecolor="none" ) # vmin=self.vmin, vmax=self.vmax, cb = self.plotw_quat.fig.colorbar( quat.mappable, cax=self.cbax_quat, extend=extend, format=autocolorbarformat((fom.min(), fom.max())) ) cb.set_label(fomlabel, fontsize=18) quat.set_projection(azim=azim, elev=elev) if self.calctype == 0: quat.line(self.compverts[0], self.compverts[1]) self.quatcalc.plotfomalonglineparameter( self.plotw_tern.axes, self.lineparameter, fomselect, compend1=self.compverts[0], compend2=self.compverts[1], lineparticks=numpy.linspace(0, 1, 4), ls="none", marker=".", ) elif self.calctype == 1: self.quatcalc.plotfominselectedplane( self.plotw_tern.axes, self.xyparr, fomselect, xyp_verts=self.xyp_verts, vertcomps_labels=[self.compverts[0], self.compverts[1], self.compverts[2]], s=20, edgecolor="none", cmap=cmap, norm=norm, ) quat.line(self.compverts[0], self.compverts[1]) quat.line(self.compverts[0], self.compverts[2]) quat.line(self.compverts[2], self.compverts[1]) cb = self.plotw_tern.fig.colorbar( quat.mappable, cax=self.cbax_tern, extend=extend, format=autocolorbarformat((fom.min(), fom.max())) ) cb.set_label(fomlabel, fontsize=18) self.plotw_quat.axes.mouse_init() self.plotw_quat.axes.set_axis_off() self.plotw_tern.fig.canvas.draw() self.plotw_quat.fig.canvas.draw()
pylab.figure() #axq=pylab.subplot(111) stpqp=QuaternaryPlot(111, ellabels=ellabels) selectinds, distfromplane, xyparr, xyp_verts,intriangle=stpqp.filterbydistancefromplane(comps, compvertsp[0], compvertsp[1], compvertsp[2], critdistp, withintriangle=betweenbool, invlogic=invertbool, returnall=True) xyparr=xyparr[selectinds] cols=stpqp.rgb_comp(comps[selectinds]) stpqp.plotbycolor(comps[selectinds], cols, marker='o', markersize=3, alpha=1) stpqp.line(compvertsp[0], compvertsp[1], lw=2) stpqp.line(compvertsp[2], compvertsp[1], lw=2) stpqp.line(compvertsp[0], compvertsp[2], lw=2) #stpqp.scatter(comps[selectinds], pointsize stpqp.set_projection(azim=view_azim, elev=view_elev) stpqp.label(fontsize=20) pylab.savefig(os.path.join(savefolder, 'QuatPointsPlane.png')) pylab.savefig(os.path.join(savefolder, 'QuatPointsPlane.eps')) pylab.figure() #axq=pylab.subplot(111) stpql=QuaternaryPlot(111, ellabels=ellabels)
compend1, compend2, critdist, betweenpoints=betweenpoints, invlogic=False, returnall=True) indsnot = q2.filterbydistancefromline(comps, compend1, compend2, critdist, betweenpoints=betweenpoints, invlogic=True) print len(inds), ' points' q2.scatter(comps[inds], c=comps[inds, 3]) q2.scatter(comps[indsnot], c='grey', marker='.', s=5) q2.line(compend1, compend2) q2.label(ha='center', va='center', fontsize=16) q2.set_projection(azim=-17, elev=-6) pylab.figure() lp = lineparameter[inds] argsinds = numpy.argsort(lp) pylab.plot(lp[argsinds], comps[inds, 3][argsinds], 'b-') pylab.plot(lp[argsinds], comps[inds, 3][argsinds], 'bo') ax = pylab.gca() lineparticks = numpy.linspace(0, 1, 4) tl = [] for i in lineparticks: c = compend1 + (compend2 - compend1) * i
compend1=numpy.array([0.125, .125, .6, .15]) compend2=numpy.array([.2, .2, 0., .6]) critdist=.05 betweenpoints=False q.scatter(comps,c=comps[:,3]) q.label(ha='center', va='center', fontsize=16) q.set_projection(azim=-17, elev=-6) inds, distfromlin, lineparameter=q2.filterbydistancefromline(comps, compend1, compend2, critdist, betweenpoints=betweenpoints, invlogic=False, returnall=True) indsnot=q2.filterbydistancefromline(comps, compend1, compend2, critdist, betweenpoints=betweenpoints, invlogic=True) print len(inds), ' points' q2.scatter(comps[inds],c=comps[inds,3]) q2.scatter(comps[indsnot],c='grey', marker='.', s=5) q2.line(compend1, compend2) q2.label(ha='center', va='center', fontsize=16) q2.set_projection(azim=-17, elev=-6) pylab.figure() lp=lineparameter[inds] argsinds=numpy.argsort(lp) pylab.plot(lp[argsinds], comps[inds,3][argsinds], 'b-') pylab.plot(lp[argsinds], comps[inds,3][argsinds], 'bo') ax=pylab.gca() lineparticks=numpy.linspace(0, 1, 4) tl=[] for i in lineparticks:
q=QuaternaryPlot(111) #define these to be modified for each end member z=numpy.zeros(4, dtype='float64') ctr3=numpy.ones(4, dtype='float64')/3. 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(4): a=copy.copy(z) a[i]=1. b=copy.copy(ctr3) b[i]=0. q.line(a, b, fmt='b-') q.scatter([b], c='b', s=15) endmembers+=[a] lineendpairs+=[[a, b]] #convert the end members and pairs of endpts to cartesian xyz_lineendpairs=[numpy.array(q.toCart(ls)).T for ls in lineendpairs] xyz_endmembers=numpy.array(q.toCart(endmembers)).T #choose the composition of a phase and draw the trivial phase field lines phcomp=numpy.array([.1, .3, .2, .4]) q.scatter([phcomp], c='r', s=20) for i in range(4): a=copy.copy(z) a[i]=1. q.line(a, phcomp, fmt='r-')