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 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, 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 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, 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()
# 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
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])
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')