def plotbinarylines_quat(ax, comps, fom, ellabels=['A', 'B', 'C', 'D'], legloc=4, **kwargs): cb = comps > .001 qtemp = QuaternaryPlot(None) ms = ['<', '>', '^', 'v', 's', 'D'] # for i in range(4): # barr=cb[:, i]>.999 # if not numpt.any(barr): # continue # ax.plot(c[j], y, ms[count], c=c, ms=ms, markeredgecolor='None', label='%s,%s' %(ellabels[i], ellabels[j]), **kwargs) 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 = qtemp.rgb_comp(cmps) ys = fom[barr][inds] for count2, (c, col, y) in enumerate(zip(cmps, cols, ys)): if count2 == len(ys) // 2: ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, label='%s,%s' % (ellabels[i], ellabels[j]), **kwargs) else: ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, **kwargs) #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) ax.plot([c1[j], c2[j]], [y1, y2], '-', c=col, **kwargs) try: ax.legend(loc=legloc).draggable() 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
def __init__(self, previousmm, execute=True, **kwargs): super(MainMenu, self).__init__(None) self.ui=plottypeDialog(self, **kwargs) intervs=20 compsint=[[b, c, (intervs-a-b-c), a] for a in numpy.arange(0,intervs+1)[::-1] for b in numpy.arange(0,intervs+1-a) for c in numpy.arange(0,intervs+1-a-b)][::-1] print len(compsint) comps=numpy.float32(compsint)/intervs pylab.figure() stpquat=QuaternaryPlot(111) cols=stpquat.rgb_comp(comps) self.ui.loadplotdata(comps, cols) if execute: self.ui.exec_()
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 __init__(self, parent=None, title='', folderpath=None): super(dialog, self).__init__(parent) plotw = plotwidget(self) ax = plotw.axes intervs = 20 compsint = [[b, c, (intervs - a - b - c), a] for a in numpy.arange(0, intervs + 1)[::-1] for b in numpy.arange(0, intervs + 1 - a) for c in numpy.arange(0, intervs + 1 - a - b)][::-1] print len(compsint) comps = numpy.float32(compsint) / intervs pylab.figure() stpquat = QuaternaryPlot(111) cols = stpquat.rgb_comp(comps) stpquat.scatter(comps, c=cols, s=100, edgecolors='none') stpquat.label() self.tf = ternaryfaces_shells(ax, nintervals=intervs) self.tf.label() self.tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') QObject.connect(plotw, SIGNAL("genericclickonplot"), self.plotclick) mainlayout = QGridLayout() mainlayout.addWidget(plotw, 0, 0) self.setLayout(mainlayout)
def __init__(self, previousmm, execute=True, **kwargs): super(MainMenu, self).__init__(None) self.ui = plottypeDialog(self, **kwargs) intervs = 20 compsint = [[b, c, (intervs - a - b - c), a] for a in numpy.arange(0, intervs + 1)[::-1] for b in numpy.arange(0, intervs + 1 - a) for c in numpy.arange(0, intervs + 1 - a - b)][::-1] print len(compsint) comps = numpy.float32(compsint) / intervs pylab.figure() stpquat = QuaternaryPlot(111) cols = stpquat.rgb_comp(comps) self.ui.loadplotdata(comps, cols) if execute: self.ui.exec_()
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 __init__(self, parent=None, title='', folderpath=None): super(dialog, self).__init__(parent) plotw=plotwidget(self) ax=plotw.axes intervs=20 compsint=[[b, c, (intervs-a-b-c), a] for a in numpy.arange(0,intervs+1)[::-1] for b in numpy.arange(0,intervs+1-a) for c in numpy.arange(0,intervs+1-a-b)][::-1] print len(compsint) comps=numpy.float32(compsint)/intervs pylab.figure() stpquat=QuaternaryPlot(111) cols=stpquat.rgb_comp(comps) stpquat.scatter(comps, c=cols, s=100, edgecolors='none') stpquat.label() self.tf=ternaryfaces(ax) self.tf.label() self.tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') QObject.connect(plotw, SIGNAL("genericclickonplot"), self.plotclick) mainlayout=QGridLayout() mainlayout.addWidget(plotw, 0, 0) self.setLayout(mainlayout)
def plotbinarylines_quat(ax, comps, fom, ellabels=['A', 'B', 'C', 'D'], legloc=4, **kwargs): cb=comps>.001 qtemp=QuaternaryPlot(None) ms=['<','>','^','v','s','D'] # for i in range(4): # barr=cb[:, i]>.999 # if not numpt.any(barr): # continue # ax.plot(c[j], y, ms[count], c=c, ms=ms, markeredgecolor='None', label='%s,%s' %(ellabels[i], ellabels[j]), **kwargs) 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=qtemp.rgb_comp(cmps) ys=fom[barr][inds] for count2, (c, col, y) in enumerate(zip(cmps, cols, ys)): if count2==len(ys)//2: ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, label='%s,%s' %(ellabels[i], ellabels[j]), **kwargs) else: ax.plot(c[j], y, marker=ms[count], c=col, markeredgecolor=col, **kwargs) #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) ax.plot([c1[j], c2[j]], [y1, y2], '-', c=col, **kwargs) try: ax.legend(loc=legloc).draggable() except: pass
def __init__(self, comps, parent=None, title='', folderpath=None): super(dialog, self).__init__(parent) plotw = plotwidget(self) ax = plotw.axes inds = np.where(comps[:, -1] == 0.)[0] comps = comps[inds, :-1] #print comps.shape stpquat = QuaternaryPlot(ax) ax.cla() cols = stpquat.rgb_comp(comps) #stpquat.scatter(comps, c=cols, s=100, edgecolors='none') #stpquat.label() self.tf = ternaryfaces_shells(ax, nintervals=intervs) self.tf.label() self.tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') #only select comps plotw2 = plotwidget(self, projection3d=True) ax = plotw2.axes #unary stpquat = QuaternaryPlot(ax) stpquat.scatter(comps, c=cols, s=100, edgecolors='none') stpquat.label() QObject.connect(plotw, SIGNAL("genericclickonplot"), self.plotclick) QObject.connect(plotw2, SIGNAL("genericclickonplot"), self.plotclick) mainlayout = QGridLayout() mainlayout.addWidget(plotw, 0, 0) mainlayout.addWidget(plotw2, 1, 0) self.setLayout(mainlayout)
def __init__(self, comps, parent=None, title='', folderpath=None): super(dialog, self).__init__(parent) plotw=plotwidget(self) ax=plotw.axes inds=np.where(comps[:, -1]==0.)[0] comps=comps[inds, :-1] #print comps.shape stpquat=QuaternaryPlot(ax) ax.cla() cols=stpquat.rgb_comp(comps) #stpquat.scatter(comps, c=cols, s=100, edgecolors='none') #stpquat.label() self.tf=ternaryfaces_shells(ax, nintervals=intervs) self.tf.label() self.tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') #only select comps plotw2=plotwidget(self, projection3d=True) ax=plotw2.axes #unary stpquat=QuaternaryPlot(ax) stpquat.scatter(comps, c=cols, s=100, edgecolors='none') stpquat.label() QObject.connect(plotw, SIGNAL("genericclickonplot"), self.plotclick) QObject.connect(plotw2, SIGNAL("genericclickonplot"), self.plotclick) mainlayout=QGridLayout() mainlayout.addWidget(plotw, 0, 0) mainlayout.addWidget(plotw2, 1, 0) self.setLayout(mainlayout)
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
dropd[k]=numpy.array(dropd[k]) f.close() dropd['compositions']=numpy.array([dropd[elkey] for elkey in elkeys]).T comps=numpy.array([dropd[elkey] for elkey in elkeys]).T gridi=30 comps30=[(a*1./gridi, b*1./gridi, c*1./gridi, (gridi-a-b-c)*1./gridi) for a in numpy.arange(0,1+gridi) for b in numpy.arange(0,1+gridi-a) for c in numpy.arange(0,1+gridi-a-b)] pylab.figure() #axq=pylab.subplot(111) stpq=QuaternaryPlot(111, ellabels=ellabels) cols=stpq.rgb_comp(comps30) stpq.plotbycolor(comps30, cols, marker='o', markersize=3, alpha=1) stpq.set_projection(azim=view_azim, elev=view_elev) pylab.savefig(os.path.join(savefolder, 'QuatPointsAll.png')) pylab.savefig(os.path.join(savefolder, 'QuatPointsAll.eps')) pylab.figure() #axq=pylab.subplot(111) stpqp=QuaternaryPlot(111, ellabels=ellabels)
import pylab, numpy, copy, itertools from myquaternaryutility import QuaternaryPlot from mpl_toolkits.mplot3d.art3d import Poly3DCollection def samesside(p,q,a,b): cp1=numpy.cross(b-a,p-a) cp2=numpy.cross(b-a,q-a) return numpy.dot(cp1,cp2)>0. def intriangle(p, trianglepoints): return not (False in [samesside(p,*triperm) for triperm in itertools.permutations(trianglepoints)]) 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
# Data for uniform Point-Distribution compsint = [[b, c, (intervs - a - b - c), a] for a in np.arange(0, intervs + 1)[::-1] for b in np.arange(0, intervs + 1 - a) for c in np.arange(0, intervs + 1 - a - b)][::-1] print len(compsint) comps = np.float32(compsint) / intervs # Declaration of the figure with the given number of columns and rows fig, axis = plt.subplots(nrows=nrows, ncols=ncols, sharex=True, sharey=True) # Iteration over every axis where the data is used to plot the ternary_shells points_list = [] for i in range(0, nrows, 1): for j in range(0, ncols, 1): # Get the object QuaternaryPlot stpquat = QuaternaryPlot() cols = stpquat.rgb_comp(comps) tf = ternaryfaces_shells(axis[i][j], ellabels, nintervals=intervs) tf.label() #Saves all tthe picked data inside a list for the color changing points_list.append(tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s=None)) # Pick event for changing color of the picked Data def onpick(event): event.artist._facecolors[event.ind, :] = (1, 0, 0, 1) fig.canvas.draw() # A Press event executed on mouse-clicks # It takes the clicked coordinates and turns them into the comp coordinates # Closes the program after reaching the number of measurments
rgb_cmy=lambda a:1.-a rgb_cmyk=lambda a:rgb_cmy(cmy_cmyk(a)) return rgb_cmyk(cmp) fig=pylab.figure() ax=pylab.subplot(111) ax.set_aspect(1) for d in dlist: mark=marks[codeset.index(d['code'])] col=rgb_comp(d['compositions']) if d['compositions'].sum==0: pylab.scatter(d['x'], d['y'],color=col,s=14,marker=mark, edgecolor='k') else: pylab.scatter(d['x'], d['y'],color=col,s=14,marker=mark, edgecolor='none') for cd, ma in zip(codeset, marks): pylab.plot([], [], 'k'+ma, mec='none', label=`cd`) pylab.legend(loc=6) sys.path.append(r'D:\Google Drive\Documents\PythonCode\JCAP\PythonCompositionPlots') from myquaternaryutility import QuaternaryPlot pylab.figure() carr=numpy.array([d['compositions'] for d in dlist]) stpq=QuaternaryPlot(111) stpq.scatter(carr) pylab.show() errortime
if SYSTEM==0: elkeys=['Ni', 'Fe', 'Co', 'Ce'] pl=[] pl+=['C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/results/20130402NiFeCoCe_Plate1_5500_dlist.dat'] pl+=['C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/results/20130403NiFeCoCe_Plate2_5498_dlist.dat'] pl+=['C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/results/20130403NiFeCoCe_Plate3_4835_dlist.dat'] compend1=numpy.array([.5, .5, .0, .0]) compend2=numpy.array([.27, 0, .27, .46]) critdist=.06 savep='C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/parsedresults/201304NiFeCoCe_compline%.2f_plate123_dlist.dat' %critdist savep2='C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/parsedresults/201304NiFeCoCe_compline%.2f_linedetails.dat' %critdist savep3='C:/Users/gregoire/Documents/EchemDropRawData/NiFeCoCe/parsedresults/201304NiFeCoCe_compline%.2f_samples.txt' %critdist betweenpoints=False stpq=QuaternaryPlot(111) platesdlist=[] plotcomps=[] lined={} lined['distfromlin']=[] lined['lineparameter']=[] lined['compend1']=compend1 lined['compend2']=compend2 lined['critdist']=critdist lined['betweenpoints']=betweenpoints for p in pl: f=open(p, mode='r') dlist=pickle.load(f) f.close() comps=numpy.array([d['compositions'] for d in dlist])
from quaternary_faces_shells import ternaryfaces_shells from myquaternaryutility import QuaternaryPlot intervs=10 compsint=[[b, c, (intervs-a-b-c), a] for a in numpy.arange(0,intervs+1)[::-1] for b in numpy.arange(0,intervs+1-a) for c in numpy.arange(0,intervs+1-a-b)][::-1] print len(compsint) comps=numpy.float32(compsint)/intervs pylab.figure() stpquat=QuaternaryPlot(111) cols=stpquat.rgb_comp(comps) stpquat.scatter(comps, c=cols, s=1200, edgecolors='none') stpquat.label() pylab.figure() ax=pylab.gca() tf=ternaryfaces_shells(ax, nintervals=intervs) tf.label() #inds_x_y=tf.toCart(comps) tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') #pylab.figure(figsize=(12, 4)) #tf.quatscatter(comps, cols, s=200, fontsize=0, azim=72, elev=20, edgecolor='none', outline=True)
def samesside(p, q, a, b): cp1 = numpy.cross(b - a, p - a) cp2 = numpy.cross(b - a, q - a) return numpy.dot(cp1, cp2) > 0. def intriangle(p, trianglepoints): return not (False in [ samesside(p, *triperm) for triperm in itertools.permutations(trianglepoints) ]) 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]
import pylab, numpy from myquaternaryutility import QuaternaryPlot q=QuaternaryPlot(111) #t=numpy.linspace(0,1.,5) #comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] #comps=numpy.float32(comps) t=numpy.linspace(0,1.,30) comps=[[a,b,1.-a-b-(2.*a**2+b),2.*a**2+b] for a in t for b in t[:10] if a+b+(2.*a**2+b)<=1.] comps=numpy.float32(comps) x, y, z=q.toCart(comps) q.scatter(comps,c=comps[:,3]) #q.ax.scatter(x, y, z, c=z) q.plotabcprojection(comps, c=(.4, .4, .4)) q.label(ha='center', va='center', fontsize=16) q.set_projection(azim=-17, elev=-6) pylab.show()
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)
import pylab, numpy from myquaternaryutility import QuaternaryPlot q = QuaternaryPlot(211) q2 = QuaternaryPlot(212) #t=numpy.linspace(0,1.,5) #comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] #comps=numpy.float32(comps) t = numpy.linspace(0, 1., 30) comps = [[a, b, 1. - a - b - (2. * a**2 + b), 2. * a**2 + b] for a in t for b in t[:10] if a + b + (2. * a**2 + b) <= 1.] comps = numpy.float32(comps) examplenum = 0 if examplenum == 0: compvert2 = numpy.array([0.125, .125, .6, .15]) compvert0 = numpy.array([.2, .2, 0., .6]) compvert1 = numpy.array([1., 0., 0., 0]) critdist = .04 withintriangle = False elif examplenum == 1: compvert2 = numpy.array([0.125, .125, .6, .15]) compvert0 = numpy.array([.2, .2, 0., .6]) compvert1 = numpy.array([1., 0., 0., 0]) critdist = .04 withintriangle = True q.scatter(comps, c=comps[:, 3])
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 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()
def __init__(self, parent, echem30_select, echem30_all, title="", folderpath=None, ellabels=["A", "B", "C", "D"]): super(quatsliceDialog, self).__init__(parent) self.parent = parent self.echem30_select = echem30_select self.echem30_all = echem30_all self.ellabels = ellabels self.dataclass = fomdatapreset() self.plotw_quat = plotwidget(self, projection3d=True) self.plotw_tern = plotwidget(self) axrect = [0.85, 0.1, 0.04, 0.8] self.plotw_tern.fig.subplots_adjust(left=0.1, right=axrect[0] - 0.08) self.cbax_tern = self.plotw_tern.fig.add_axes(axrect) QObject.connect(self.plotw_tern, SIGNAL("genericclickonplot"), self.ternclickprocess) self.plotw_quat.fig.subplots_adjust(left=0, right=axrect[0] - 0.08) self.cbax_quat = self.plotw_quat.fig.add_axes(axrect) ternskipComboBoxLabel = QLabel() ternskipComboBoxLabel.setText("Exclude for ternary:") self.ternskipComboBox = QComboBox() for i, l in enumerate(["A", "B", "C", "D"]): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(i) ternskiplayout = QHBoxLayout() ternskiplayout.addWidget(ternskipComboBoxLabel) ternskiplayout.addWidget(self.ternskipComboBox) self.compcutComboBox = QComboBox() for i, nam in enumerate(["1-D (pseudobinary)", "2-D (pseudoternnary)"]): self.compcutComboBox.insertItem(i, nam) self.compcutComboBox.setCurrentIndex(0) self.systemsComboBox = QComboBox() self.systemsinds = [-1, 0] self.systemsComboBox.insertItem(999, "select files") self.systemsComboBox.insertItem(999, "update style") for ind, nam in self.dataclass.systemoptions: self.systemsComboBox.insertItem(999, nam) self.systemsinds += [ind] self.systemsComboBox.setCurrentIndex(0) sl = ["0.", "0.", "1.", "0.", "0.", "0."] self.complineeditlist = [] for i in range(3): self.complineeditlist += [QLineEdit()] self.complineeditlist[-1].setText(", ".join(sl[2 - i : 2 - i + 4])) compLabel = QLabel() compLabel.setText("Composition points") folderButton = QPushButton() folderButton.setText("select\nfolder") QObject.connect(folderButton, SIGNAL("pressed()"), self.selectfolder) plotButton = QPushButton() plotButton.setText("update\nfigures") QObject.connect(plotButton, SIGNAL("pressed()"), self.calcandplot) saveButton = QPushButton() saveButton.setText("Save figs\n+ Samples") QObject.connect(saveButton, SIGNAL("pressed()"), self.save) templab = QLabel() templab.setText("Crit Comp. Dist") self.critdistSpinBox = QDoubleSpinBox() self.critdistSpinBox.setDecimals(3) critdistlayout = QHBoxLayout() critdistlayout.addWidget(templab) critdistlayout.addWidget(self.critdistSpinBox) self.compboundCheckBox = QCheckBox() self.compboundCheckBox.setText("restrict composition\nselection boundaries") self.invertCheckBox = QCheckBox() self.invertCheckBox.setText("invert selection") self.revcmapCheckBox = QCheckBox() self.revcmapCheckBox.setText("reverse cmap?") templab = QLabel() templab.setText("min,max colorbar") self.vminmaxLineEdit = QLineEdit() vminmaxlayout = QVBoxLayout() vminmaxlayout.addWidget(templab) vminmaxlayout.addWidget(self.vminmaxLineEdit) templab = QLabel() templab.setText("azim,elev tetr.") self.azimelevLineEdit = QLineEdit() azimelevlayout = QVBoxLayout() azimelevlayout.addWidget(templab) azimelevlayout.addWidget(self.azimelevLineEdit) self.azimelevLineEdit.setText("-159,30") templab = QLabel() templab.setText('below,above range colors:\nEnter a char,0-1 gray,tuple,\n"None" for ignore') self.aboverangecolLineEdit = QLineEdit() self.aboverangecolLineEdit.setText("k") self.belowrangecolLineEdit = QLineEdit() self.belowrangecolLineEdit.setText("0.9") outrangecollayout = QGridLayout() outrangecollayout.addWidget(templab, 0, 0, 2, 1) outrangecollayout.addWidget(self.belowrangecolLineEdit, 0, 1) outrangecollayout.addWidget(self.aboverangecolLineEdit, 1, 1) templab = QLabel() templab.setText("FOM shift:") self.fomshiftSpinBox = QDoubleSpinBox() self.fomshiftSpinBox.setDecimals(3) fomshiftlayout = QHBoxLayout() fomshiftlayout.addWidget(templab) fomshiftlayout.addWidget(self.fomshiftSpinBox) templab = QLabel() templab.setText("FOM scaling:") self.fomscaleSpinBox = QDoubleSpinBox() self.fomscaleSpinBox.setMaximum(1000.0) self.fomscaleSpinBox.setMinimum(-1000.0) self.fomscaleSpinBox.setValue(1.0) fomscalelayout = QHBoxLayout() fomscalelayout.addWidget(templab) fomscalelayout.addWidget(self.fomscaleSpinBox) mainlayout = QGridLayout() ctrllayout = QGridLayout() ctrllayout.addWidget(plotButton, 0, 0) ctrllayout.addWidget(self.compcutComboBox, 0, 1) ctrllayout.addWidget(saveButton, 0, 2) ctrllayout.addWidget(self.systemsComboBox, 0, 3) ctrllayout.addWidget(compLabel, 1, 0) ctrllayout.addWidget(self.complineeditlist[0], 1, 1) ctrllayout.addWidget(self.complineeditlist[1], 1, 2) ctrllayout.addWidget(self.complineeditlist[2], 1, 3) ctrllayout.addWidget(self.compboundCheckBox, 2, 0) ctrllayout.addWidget(self.invertCheckBox, 2, 1) ctrllayout.addLayout(critdistlayout, 2, 2, 1, 2) ctrllayout.addWidget(self.revcmapCheckBox, 3, 0) ctrllayout.addLayout(vminmaxlayout, 3, 1) ctrllayout.addLayout(outrangecollayout, 3, 2, 1, 2) ctrllayout.addLayout(ternskiplayout, 4, 0) # ctrllayout.addLayout(fomshiftlayout, 4, 1) # ctrllayout.addLayout(fomscalelayout, 4, 2) ctrllayout.addLayout(azimelevlayout, 4, 1, 1, 2) mainlayout.addLayout(ctrllayout, 0, 0, 2, 1) mainlayout.addWidget(self.plotw_quat, 3, 0) mainlayout.addWidget(self.plotw_tern, 4, 0) # mainlayout.addWidget(self.plotw_30select, 0, 1, 2, 8) # mainlayout.addWidget(self.plotw_30all, 2, 1, 2, 8) self.setLayout(mainlayout) self.folderpath = folderpath self.ternskipComboBox.clear() for i, l in enumerate(self.ellabels): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(3) self.selectsystem = None self.quatcalc = QuaternaryPlot(111, ellabels=self.ellabels) self.resize(600, 850)
class quatsliceDialog(QDialog): def __init__(self, parent, echem30_select, echem30_all, title="", folderpath=None, ellabels=["A", "B", "C", "D"]): super(quatsliceDialog, self).__init__(parent) self.parent = parent self.echem30_select = echem30_select self.echem30_all = echem30_all self.ellabels = ellabels self.dataclass = fomdatapreset() self.plotw_quat = plotwidget(self, projection3d=True) self.plotw_tern = plotwidget(self) axrect = [0.85, 0.1, 0.04, 0.8] self.plotw_tern.fig.subplots_adjust(left=0.1, right=axrect[0] - 0.08) self.cbax_tern = self.plotw_tern.fig.add_axes(axrect) QObject.connect(self.plotw_tern, SIGNAL("genericclickonplot"), self.ternclickprocess) self.plotw_quat.fig.subplots_adjust(left=0, right=axrect[0] - 0.08) self.cbax_quat = self.plotw_quat.fig.add_axes(axrect) ternskipComboBoxLabel = QLabel() ternskipComboBoxLabel.setText("Exclude for ternary:") self.ternskipComboBox = QComboBox() for i, l in enumerate(["A", "B", "C", "D"]): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(i) ternskiplayout = QHBoxLayout() ternskiplayout.addWidget(ternskipComboBoxLabel) ternskiplayout.addWidget(self.ternskipComboBox) self.compcutComboBox = QComboBox() for i, nam in enumerate(["1-D (pseudobinary)", "2-D (pseudoternnary)"]): self.compcutComboBox.insertItem(i, nam) self.compcutComboBox.setCurrentIndex(0) self.systemsComboBox = QComboBox() self.systemsinds = [-1, 0] self.systemsComboBox.insertItem(999, "select files") self.systemsComboBox.insertItem(999, "update style") for ind, nam in self.dataclass.systemoptions: self.systemsComboBox.insertItem(999, nam) self.systemsinds += [ind] self.systemsComboBox.setCurrentIndex(0) sl = ["0.", "0.", "1.", "0.", "0.", "0."] self.complineeditlist = [] for i in range(3): self.complineeditlist += [QLineEdit()] self.complineeditlist[-1].setText(", ".join(sl[2 - i : 2 - i + 4])) compLabel = QLabel() compLabel.setText("Composition points") folderButton = QPushButton() folderButton.setText("select\nfolder") QObject.connect(folderButton, SIGNAL("pressed()"), self.selectfolder) plotButton = QPushButton() plotButton.setText("update\nfigures") QObject.connect(plotButton, SIGNAL("pressed()"), self.calcandplot) saveButton = QPushButton() saveButton.setText("Save figs\n+ Samples") QObject.connect(saveButton, SIGNAL("pressed()"), self.save) templab = QLabel() templab.setText("Crit Comp. Dist") self.critdistSpinBox = QDoubleSpinBox() self.critdistSpinBox.setDecimals(3) critdistlayout = QHBoxLayout() critdistlayout.addWidget(templab) critdistlayout.addWidget(self.critdistSpinBox) self.compboundCheckBox = QCheckBox() self.compboundCheckBox.setText("restrict composition\nselection boundaries") self.invertCheckBox = QCheckBox() self.invertCheckBox.setText("invert selection") self.revcmapCheckBox = QCheckBox() self.revcmapCheckBox.setText("reverse cmap?") templab = QLabel() templab.setText("min,max colorbar") self.vminmaxLineEdit = QLineEdit() vminmaxlayout = QVBoxLayout() vminmaxlayout.addWidget(templab) vminmaxlayout.addWidget(self.vminmaxLineEdit) templab = QLabel() templab.setText("azim,elev tetr.") self.azimelevLineEdit = QLineEdit() azimelevlayout = QVBoxLayout() azimelevlayout.addWidget(templab) azimelevlayout.addWidget(self.azimelevLineEdit) self.azimelevLineEdit.setText("-159,30") templab = QLabel() templab.setText('below,above range colors:\nEnter a char,0-1 gray,tuple,\n"None" for ignore') self.aboverangecolLineEdit = QLineEdit() self.aboverangecolLineEdit.setText("k") self.belowrangecolLineEdit = QLineEdit() self.belowrangecolLineEdit.setText("0.9") outrangecollayout = QGridLayout() outrangecollayout.addWidget(templab, 0, 0, 2, 1) outrangecollayout.addWidget(self.belowrangecolLineEdit, 0, 1) outrangecollayout.addWidget(self.aboverangecolLineEdit, 1, 1) templab = QLabel() templab.setText("FOM shift:") self.fomshiftSpinBox = QDoubleSpinBox() self.fomshiftSpinBox.setDecimals(3) fomshiftlayout = QHBoxLayout() fomshiftlayout.addWidget(templab) fomshiftlayout.addWidget(self.fomshiftSpinBox) templab = QLabel() templab.setText("FOM scaling:") self.fomscaleSpinBox = QDoubleSpinBox() self.fomscaleSpinBox.setMaximum(1000.0) self.fomscaleSpinBox.setMinimum(-1000.0) self.fomscaleSpinBox.setValue(1.0) fomscalelayout = QHBoxLayout() fomscalelayout.addWidget(templab) fomscalelayout.addWidget(self.fomscaleSpinBox) mainlayout = QGridLayout() ctrllayout = QGridLayout() ctrllayout.addWidget(plotButton, 0, 0) ctrllayout.addWidget(self.compcutComboBox, 0, 1) ctrllayout.addWidget(saveButton, 0, 2) ctrllayout.addWidget(self.systemsComboBox, 0, 3) ctrllayout.addWidget(compLabel, 1, 0) ctrllayout.addWidget(self.complineeditlist[0], 1, 1) ctrllayout.addWidget(self.complineeditlist[1], 1, 2) ctrllayout.addWidget(self.complineeditlist[2], 1, 3) ctrllayout.addWidget(self.compboundCheckBox, 2, 0) ctrllayout.addWidget(self.invertCheckBox, 2, 1) ctrllayout.addLayout(critdistlayout, 2, 2, 1, 2) ctrllayout.addWidget(self.revcmapCheckBox, 3, 0) ctrllayout.addLayout(vminmaxlayout, 3, 1) ctrllayout.addLayout(outrangecollayout, 3, 2, 1, 2) ctrllayout.addLayout(ternskiplayout, 4, 0) # ctrllayout.addLayout(fomshiftlayout, 4, 1) # ctrllayout.addLayout(fomscalelayout, 4, 2) ctrllayout.addLayout(azimelevlayout, 4, 1, 1, 2) mainlayout.addLayout(ctrllayout, 0, 0, 2, 1) mainlayout.addWidget(self.plotw_quat, 3, 0) mainlayout.addWidget(self.plotw_tern, 4, 0) # mainlayout.addWidget(self.plotw_30select, 0, 1, 2, 8) # mainlayout.addWidget(self.plotw_30all, 2, 1, 2, 8) self.setLayout(mainlayout) self.folderpath = folderpath self.ternskipComboBox.clear() for i, l in enumerate(self.ellabels): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(3) self.selectsystem = None self.quatcalc = QuaternaryPlot(111, ellabels=self.ellabels) self.resize(600, 850) def selectfolder(self, folder=None): if folder is None: self.folderpath = mygetdir(self, markstr="for saving") else: self.folderpath = folder def calcandplot(self): print "0" i = self.systemsinds[self.systemsComboBox.currentIndex()] if self.selectsystem is None or i == -1 or (i != 0 and i != self.selectsystem): self.selectsystem = i self.dataclass.readdata(self.selectsystem, qparent=self) self.comps = self.dataclass.compsall self.fom = self.dataclass.fomall self.smp = self.dataclass.smpsall self.code = self.dataclass.codeall # self.codeorig=self.dataclass.codeorig # self.smpsorig=self.dataclass.smpsorig self.ellabels = self.dataclass.ellabels self.vminmaxLineEdit.setText(` self.dataclass.vmin ` + "," + ` self.dataclass.vmax `) for le, v in zip( [self.belowrangecolLineEdit, self.aboverangecolLineEdit], [self.dataclass.belowrangecolstr, self.dataclass.aboverangecolstr], ): le.setText(` v `) i0 = self.ternskipComboBox.currentIndex() self.ternskipComboBox.clear() for i, l in enumerate(self.ellabels): self.ternskipComboBox.insertItem(i, l) self.ternskipComboBox.setCurrentIndex(i0) self.calctype = self.compcutComboBox.currentIndex() critdist = self.critdistSpinBox.value() print "1" self.compverts = [] for i in range(2 + self.calctype): sl = str(self.complineeditlist[i].text()).split(",") c = [myeval(s.strip()) for s in sl] c = c[:4] c += [0.0] * (4 - len(c)) c = numpy.float64(c) c /= c.sum() self.compverts += [c] betweenbool = self.compboundCheckBox.isChecked() invertbool = self.invertCheckBox.isChecked() if self.calctype == 0: self.selectinds, distfromlin, self.lineparameter = self.quatcalc.filterbydistancefromline( self.comps, self.compverts[0], self.compverts[1], critdist, betweenpoints=betweenbool, invlogic=invertbool, returnall=True, ) self.lineparameter = self.lineparameter[self.selectinds] elif self.calctype == 1: self.selectinds, distfromplane, self.xyparr, self.xyp_verts, intriangle = self.quatcalc.filterbydistancefromplane( self.comps, self.compverts[0], self.compverts[1], self.compverts[2], critdist, withintriangle=betweenbool, invlogic=invertbool, returnall=True, ) self.xyparr = self.xyparr[self.selectinds] self.selectcomps = self.comps[self.selectinds] self.plot() 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() def ternclickprocess(self, coords_button): xc, yc, button = coords_button if self.calctype == 0: clickindsel = numpy.argmin((self.lineparameter - xc) ** 2) elif self.calctype == 1: clickindsel = numpy.argmin([(x - xc) ** 2 + (y - yc) ** 2 for x, y in self.xyparr]) cmp = self.selectcomps[clickindsel] clickind = numpy.argmin([((cmp - c) ** 2).sum() for c in self.comps]) s = self.smp[clickind] print "clicked composition is ", cmp, " sample is ", s def save(self): self.selectfolder(None) lab = str(self.systemsComboBox.currentText()) lab += "_" + self.dataclass.expstr + "_" if self.calctype == 0: lab += "1Dcut_" elif self.calctype == 1: lab += "2Dcut_" pngname = lambda sn: os.path.join(self.folderpath, lab + "_" + sn + ".png") epsname = lambda sn: os.path.join(self.folderpath, lab + "_" + sn + ".eps") for fig, saven in zip( [self.plotw_quat.fig, self.plotw_tern.fig, self.echem30_select.plotw.fig, self.echem30_all.plotw.fig], ["tetr", "projection", "stackedselect", "stackedall"], ): fig.savefig(pngname(saven)) fig.savefig(epsname(saven)) s = "\n".join([` i ` for i in self.smp[self.selectinds]])
#ax=pylab.subplot(211) #ax2=pylab.subplot(212) #pylab.subplots_adjust(left=.03, right=.97, top=.97, bottom=.03, hspace=.01) ax2=fig.add_subplot(len(dropdl), 1, count+1) ax2.set_aspect(1) mapbl=ax2.scatter(x, y, c=fom, s=60, marker='s', edgecolors='none', cmap=cmap, norm=norm) ax2.set_xlim(x.min()-2, x.max()+2) ax2.set_ylim(y.min()-2, y.max()+2) ax2.set_title('plate %d' %(count+1)) #pylab.title('CP1Ess (V) Map') figquat=pylab.figure(figsize=(8, 8)) stp = QuaternaryPlot(111, minlist=[0., 0., 0., 0.], ellabels=ellabels) stp.scatter(comp, c=fom, s=pointsize, edgecolors='none', cmap=cmap, norm=norm) stp.label(ha='center', va='center', fontsize=20) stp.set_projection(azim=view_azim, elev=view_elev) caxquat=figquat.add_axes((.83, .3, .04, .4)) cb=pylab.colorbar(stp.mappable, cax=caxquat, extend=extend) cb.set_label(fomlabel, fontsize=16) stp.ax.set_title('plate %d' %(count+1)) figquatall+=[figquat] compsall=numpy.array(compsall) fomall=numpy.array(fomall) plateindall=numpy.array(plateindall)
from myquaternaryutility import QuaternaryPlot gridi = 20 comps_10full = [(a * 1. / gridi, b * 1. / gridi, c * 1. / gridi, (gridi - a - b - c) * 1. / gridi) for a in numpy.arange(0, 1 + gridi) for b in numpy.arange(0, 1 + gridi - a) for c in numpy.arange(0, 1 + gridi - a - b)] comps_10full = list(set(comps_10full)) print len(comps_10full) #comps_10full=[[1., 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] comps_10full = numpy.array(comps_10full) pylab.figure() stpquat = QuaternaryPlot(111) cols = stpquat.rgb_comp(comps_10full) stpquat.scatter(comps_10full, c=cols, s=20, edgecolors='none') stpquat.label() pylab.figure() ax = pylab.gca() tf = ternaryfaces(ax, nintervals=gridi) tf.label() #inds_x_y=tf.toCart(comps_10full) tf.scatter(comps_10full, cols, skipinds=[0, 1, 2, 3], s='patch') pylab.show()
##f.close() # sys.path.append('C:/Users/Gregoire/Documents/PythonCode/ternaryplot') from myquaternaryutility import QuaternaryPlot from quaternary_FOM_stackedtern20 import * axl, stpl=make20ternaxes() # #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]) carr=numpy.array(comps) pylab.figure() stpq=QuaternaryPlot(111) #stpq.scatter(carr) cols=stpq.rgb_comp(carr) stpq.scatter(carr, c=cols, s=20, edgecolors='none') scatter_20axes(carr, cols, stpl, s=20, edgecolors='none', cb=False) stpq.label() #axl[0].figure.savefig('C:/Users/Gregoire/Documents/CaltechWork/platemaps/nestedtetr/test2.png') pylab.show()
import pylab, numpy from myquaternaryutility import QuaternaryPlot q=QuaternaryPlot(211) q2=QuaternaryPlot(212) #t=numpy.linspace(0,1.,5) #comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] #comps=numpy.float32(comps) t=numpy.linspace(0,1.,30) comps=[[a,b,1.-a-b-(2.*a**2+b),2.*a**2+b] for a in t for b in t[:10] if a+b+(2.*a**2+b)<=1.] comps=numpy.float32(comps) examplenum=1 if examplenum==0: compend1=numpy.array([.2, .4, .3, .1]) compend2=numpy.array([.2, 0, .2, .6]) critdist=.1 betweenpoints=False elif examplenum==1: compend1=numpy.array([0.1, .1, .8, 0]) compend2=numpy.array([.2, .2, 0., .6]) critdist=.05 betweenpoints=False elif examplenum==2: compend1=numpy.array([0.125, .125, .6, .15]) compend2=numpy.array([.2, .2, 0., .6]) critdist=.05
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()
#ax2=pylab.subplot(212) #pylab.subplots_adjust(left=.03, right=.97, top=.97, bottom=.03, hspace=.01) ax2=fig.add_subplot(len(dropdl), 1, count+1) ax2.set_aspect(1) mapbl=ax2.scatter(x, y, c=fom, s=60, marker='s', edgecolors='none', cmap=cmap, norm=norm) ax2.set_xlim(x.min()-2, x.max()+2) ax2.set_ylim(y.min()-2, y.max()+2) ax2.set_title('plate %d' %(count+1)) #pylab.title('CP1Ess (V) Map') comp=numpy.array([[dropd['A'][i], dropd['B'][i], dropd['C'][i], dropd['D'][i]] for i in dropinds]) comp=numpy.array([a/a.sum() for a in comp]) figquat=pylab.figure(figsize=(8, 8)) stp = QuaternaryPlot(111, minlist=[0., 0., 0., 0.], ellabels=ellabels) stp.scatter(comp, c=fom, s=pointsize, edgecolors='none', cmap=cmap, norm=norm) stp.label(ha='center', va='center', fontsize=16) stp.set_projection(azim=view_azim, elev=view_elev) caxquat=figquat.add_axes((.83, .3, .04, .4)) cb=pylab.colorbar(stp.mappable, cax=caxquat, extend=extend) cb.set_label(fomlabel, fontsize=16) stp.ax.set_title('plate %d' %(count+1)) compsall+=list(comp) fomall+=list(fom) figquatall+=[figquat] plateindall+=[count]*len(fom)
import operator, copy, os from quaternary_faces_shells import ternaryfaces_shells from myquaternaryutility import QuaternaryPlot intervs = 10 compsint = [[b, c, (intervs - a - b - c), a] for a in numpy.arange(0, intervs + 1)[::-1] for b in numpy.arange(0, intervs + 1 - a) for c in numpy.arange(0, intervs + 1 - a - b)][::-1] print len(compsint) comps = numpy.float32(compsint) / intervs pylab.figure() stpquat = QuaternaryPlot(111) cols = stpquat.rgb_comp(comps) stpquat.scatter(comps, c=cols, s=100, edgecolors='none') stpquat.label() pylab.figure() ax = pylab.gca() tf = ternaryfaces_shells(ax, nintervals=intervs) tf.label() #inds_x_y=tf.toCart(comps) tf.scatter(comps, cols, skipinds=[0, 1, 2, 3], s='patch') #pylab.figure(figsize=(12, 4)) #tf.quatscatter(comps, cols, s=200, fontsize=0, azim=72, elev=20, edgecolor='none', outline=True) #pylab.subplots_adjust(left=0, right=1, bottom=0, top=1, wspace=0, hspace=0)
from myquaternaryutility import QuaternaryPlot from quaternary_FOM_stackedtern10 import * ellabels=['Aa', 'Bb', 'Cc', 'Dd'] axl, stpl=make10ternaxes(ellabels=ellabels) gridi=30 comps_10full=[(a*1./gridi, b*1./gridi, c*1./gridi, (gridi-a-b-c)*1./gridi) for a in numpy.arange(0,1+gridi) for b in numpy.arange(0,1+gridi-a) for c in numpy.arange(0,1+gridi-a-b)] comps_10full=list(set(comps_10full)) print len(comps_10full) #plotpoints_cmyk comps_10full=numpy.array(comps_10full) pylab.figure() stpquat=QuaternaryPlot(111, ellabels=ellabels) cols=stpquat.rgb_comp(comps_10full) stpquat.scatter(comps_10full, c=cols, s=20, edgecolors='none') norm=colors.Normalize(vmin=0, vmax=1) cmap=cm.jet scatter_10axes(comps_10full, cols, stpl, s=20, edgecolors='none', cb=True, norm=norm, cmap=cmap) stpquat.label() pylab.savefig('stackedtern_quat.png') pylab.figure(axl[0].figure.number) pylab.savefig('stackedtern.png') pylab.show()
dropd={} for l in dr: for kr in l.keys(): k=kr.strip() if not k in dropd.keys(): dropd[k]=[] dropd[k]+=[myeval(l[kr].strip())] for k in dropd.keys(): dropd[k]=numpy.array(dropd[k]) f.close() dropd['compositions']=numpy.array([dropd[elkey] for elkey in elkeys]).T 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)
import pylab, numpy from myquaternaryutility import QuaternaryPlot q = QuaternaryPlot(211) q2 = QuaternaryPlot(212) # t=numpy.linspace(0,1.,5) # comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] # comps=numpy.float32(comps) t = numpy.linspace(0, 1.0, 30) comps = [ [a, b, 1.0 - a - b - (2.0 * a ** 2 + b), 2.0 * a ** 2 + b] for a in t for b in t[:10] if a + b + (2.0 * a ** 2 + b) <= 1.0 ] comps = numpy.float32(comps) examplenum = 0 if examplenum == 0: compvert2 = numpy.array([0.125, 0.125, 0.6, 0.15]) compvert0 = numpy.array([0.2, 0.2, 0.0, 0.6]) compvert1 = numpy.array([1.0, 0.0, 0.0, 0]) critdist = 0.04 withintriangle = False elif examplenum == 1: compvert2 = numpy.array([0.125, 0.125, 0.6, 0.15]) compvert0 = numpy.array([0.2, 0.2, 0.0, 0.6]) compvert1 = numpy.array([1.0, 0.0, 0.0, 0])
import pylab, numpy from myquaternaryutility import QuaternaryPlot q = QuaternaryPlot(111) #t=numpy.linspace(0,1.,5) #comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] #comps=numpy.float32(comps) t = numpy.linspace(0, 1., 30) comps = [[a, b, 1. - a - b - (2. * a**2 + b), 2. * a**2 + b] for a in t for b in t[:10] if a + b + (2. * a**2 + b) <= 1.] comps = numpy.float32(comps) x, y, z = q.toCart(comps) q.scatter(comps, c=comps[:, 3]) #q.ax.scatter(x, y, z, c=z) q.plotabcprojection(comps, c=(.4, .4, .4)) q.label(ha='center', va='center', fontsize=16) q.set_projection(azim=-17, elev=-6) pylab.show()
f=open(newpath, mode='w') f.write('\n'.join(writelines)) f.close() sys.path.append('Z:/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() x, y=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==0]).T x2, y2=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==100]).T x3, y3=numpy.array([[d['x'], d['y']] for d in dlist if (d['code'])==200]).T xn, yn=numpy.array([[d['x'], d['y']] for d in dlist if (d['code']%100)!=0]).T pylab.plot(x, y, 'rs') pylab.plot(x2, y2, 'gs') pylab.plot(x3, y3, 'bs') pylab.plot(xn, yn, 'k.') pylab.show()
# sys.path.append('C:/Users/Gregoire/Documents/PythonCode/ternaryplot') from myquaternaryutility import QuaternaryPlot from quaternary_FOM_stackedtern20 import * axl, stpl = make20ternaxes() # #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]) carr = numpy.array(comps) pylab.figure() stpq = QuaternaryPlot(111) #stpq.scatter(carr) cols = stpq.rgb_comp(carr) stpq.scatter(carr, c=cols, s=20, edgecolors='none') scatter_20axes(carr, cols, stpl, s=20, edgecolors='none', cb=False) stpq.label() axl[0].figure.savefig( 'C:/Users/Gregoire/Documents/CaltechWork/platemaps/nestedtetr/test2.png') pylab.show()
import pylab, numpy from myquaternaryutility import QuaternaryPlot q = QuaternaryPlot(211) q2 = QuaternaryPlot(212) #t=numpy.linspace(0,1.,5) #comps=[[a,b,c,d] for a in t for b in t for c in t for d in t if a+b+c+d==1.] #comps=numpy.float32(comps) t = numpy.linspace(0, 1., 30) comps = [[a, b, 1. - a - b - (2. * a**2 + b), 2. * a**2 + b] for a in t for b in t[:10] if a + b + (2. * a**2 + b) <= 1.] comps = numpy.float32(comps) examplenum = 1 if examplenum == 0: compend1 = numpy.array([.2, .4, .3, .1]) compend2 = numpy.array([.2, 0, .2, .6]) critdist = .1 betweenpoints = False elif examplenum == 1: compend1 = numpy.array([0.1, .1, .8, 0]) compend2 = numpy.array([.2, .2, 0., .6]) critdist = .05 betweenpoints = False elif examplenum == 2: compend1 = numpy.array([0.125, .125, .6, .15]) compend2 = numpy.array([.2, .2, 0., .6]) critdist = .05