Changeset 5318 for trunk/GSASIIplot.py


Ignore:
Timestamp:
Aug 2, 2022 3:50:22 PM (3 years ago)
Author:
vondreele
Message:

Good 1st version of cluster analysis; missing docs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified trunk/GSASIIplot.py

    r5312 r5318  
    11401140    RefreshPlot()
    11411141    dlg.ShowModal()
    1142 ##### PlotSngl ################################################################     
     1142#### PlotSngl ################################################################     
    11431143def PlotSngl(G2frame,newPlot=False,Data=None,hklRef=None,Title=''):
    11441144    '''Structure factor plotting package - displays zone of reflections as rings proportional
     
    13731373        Page.canvas.draw()
    13741374       
    1375 ##### Plot1DSngl ################################################################################
     1375#### Plot1DSngl ################################################################################
    13761376def Plot1DSngl(G2frame,newPlot=False,hklRef=None,Super=0,Title=False):
    13771377    '''1D Structure factor plotting package - displays reflections as sticks proportional
     
    14901490    Draw()
    14911491   
    1492 ##### Plot3DSngl ################################################################################
     1492#### Plot3DSngl ################################################################################
    14931493def Plot3DSngl(G2frame,newPlot=False,Data=None,hklRef=None,Title=False):
    14941494    '''3D Structure factor plotting package - displays reflections as spots proportional
     
    19951995#    if firstCall: Draw('main') # draw twice the first time that graphics are displayed
    19961996
    1997 ##### PlotPatterns ################################################################################
     1997#### PlotPatterns ################################################################################
    19981998def ReplotPattern(G2frame,newPlot,plotType,PatternName=None,PickName=None):
    19991999    '''This does the same as PlotPatterns except that it expects the information
     
    30513051            return '_'+string
    30523052
    3053     ###### beginning PlotPatterns execution
     3053#### beginning PlotPatterns execution
    30543054    global exclLines,Page
    30553055    global DifLine # BHT: probably does not need to be global
     
    50975097        ax0.legend(legLine,legLbl,loc='best',prop={'size':plotOpt['labelSize']})
    50985098   
    5099 ##### PlotDeltSig #############################################################
     5099#### PlotDeltSig #############################################################
    51005100def PlotDeltSig(G2frame,kind,PatternName=None):
    51015101    'Produces normal probability plot for a powder or single crystal histogram'
     
    51775177    Page.canvas.draw()
    51785178       
    5179 ##### PlotISFG ################################################################
     5179#### PlotISFG ################################################################
    51805180def PlotISFG(G2frame,data,newPlot=False,plotType='',peaks=None):
    51815181    ''' Plotting package for PDF analysis; displays I(Q), S(Q), F(Q) and G(r) as single
     
    53635363        wx.CallAfter(PlotISFG,G2frame,data,peaks=Peaks,newPlot=False)
    53645364
    5365     ##### PlotISFG continues here ############################################################
     5365#### PlotISFG continues here ############################################################
    53665366    xylim = []
    53675367    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(plotType,'mpl')
     
    56025602        Page.canvas.draw()
    56035603
    5604 ##### PlotCalib ###############################################################
     5604#### PlotCalib ###############################################################
    56055605def PlotCalib(G2frame,Inst,XY,Sigs,newPlot=False):
    56065606    '''plot of CW or TOF peak calibration
     
    56875687        Page.canvas.draw()
    56885688
    5689 ##### PlotXY ##################################################################
     5689#### PlotXY ##################################################################
    56905690def PlotXY(G2frame,XY,XY2=[],labelX='X',labelY='Y',newPlot=False,
    56915691    Title='',lines=False,names=[],names2=[],vertLines=[]):
     
    58105810   
    58115811       
    5812 ##### PlotXYZ ################################################################################
     5812#### PlotXYZ ################################################################################
    58135813def PlotXYZ(G2frame,XY,Z,labelX='X',labelY='Y',newPlot=False,Title='',zrange=None,color=None,buttonHandler=None):
    58145814    '''simple contour plot of xyz data
     
    59355935        Page.canvas.draw()
    59365936       
    5937 ##### PlotXYZvect ################################################################################
     5937#### PlotXYZvect ################################################################################
    59385938def PlotXYZvect(G2frame,X,Y,Z,R,labelX=r'X',labelY=r'Y',labelZ=r'Z',Title='',PlotName=None):
    59395939    ''' To plot a quiver of quaternion vectors colored by the rotation
     
    59815981    Page.canvas.draw()
    59825982       
    5983 ##### Plot3dXYZ ################################################################################
     5983#### Plot3dXYZ ################################################################################
    59845984def Plot3dXYZ(G2frame,nX,nY,Zdat,labelX=r'X',labelY=r'Y',labelZ=r'Z',newPlot=False,Title='',Centro=False):
    59855985   
     
    60346034        Page.canvas.draw()
    60356035       
    6036 ##### PlotAAProb ################################################################################
     6036#### PlotAAProb ################################################################################
    60376037def PlotAAProb(G2frame,resNames,Probs1,Probs2,Title='',thresh=None,pickHandler=None):
    60386038    'Needs a description'
     
    60926092    Draw()
    60936093
    6094 ##### PlotStrain ################################################################################
     6094#### PlotStrain ################################################################################
    60956095def PlotStrain(G2frame,data,newPlot=False):
    60966096    '''plot of strain data, used for diagnostic purposes
     
    61396139        Page.canvas.draw()
    61406140       
    6141 ##### PlotBarGraph ################################################################################
     6141#### PlotBarGraph ################################################################################
    61426142def PlotBarGraph(G2frame,Xarray,Xname='',Yname='Number',Title='',PlotName=None,ifBinned=False,maxBins=None):
    61436143    ''' does a vertical bar graph
     
    61836183    Page.canvas.draw()
    61846184
    6185 ##### PlotNamedFloatBarGraph ################################################################################
     6185#### PlotNamedFloatBarGraph ################################################################################
    61866186def PlotNamedFloatHBarGraph(G2frame,Xvals,Ynames,Xlabel='Value',Ylabel='',Title='',PlotName=None):
    61876187    ''' does a horizintal bar graph
     
    62196219    Page.canvas.draw()
    62206220   
    6221 ##### PlotSASDSizeDist ################################################################################
     6221#### PlotSASDSizeDist ################################################################################
    62226222def PlotSASDSizeDist(G2frame):
    62236223    'Needs a description'
     
    62716271    Page.canvas.draw()
    62726272
    6273 ##### PlotSASDPairDist ################################################################################
     6273#### PlotSASDPairDist ################################################################################
    62746274def PlotSASDPairDist(G2frame):
    62756275    'Needs a description'
     
    63126312        Page.canvas.draw()
    63136313
    6314 ##### PlotPowderLines ################################################################################
     6314#### PlotPowderLines ################################################################################
    63156315def PlotPowderLines(G2frame):
    63166316    ''' plotting of powder lines (i.e. no powder pattern) as sticks
     
    66176617        Page.canvas.draw()
    66186618   
    6619 ##### PlotSizeStrainPO ################################################################################
     6619#### PlotSizeStrainPO ################################################################################
    66206620def PlotSizeStrainPO(G2frame,data,hist='',Start=False):
    66216621    '''Plot 3D mustrain/size/preferred orientation figure. In this instance data is for a phase
     
    68976897    Page.canvas.draw()
    68986898   
    6899 ##### PlotTexture ################################################################################
     6899#### PlotTexture ################################################################################
    69006900def PlotTexture(G2frame,data,Start=False):
    69016901    '''Pole figure, inverse pole figure plotting.
     
    70887088    Page.canvas.draw()
    70897089
    7090 ##### Plot Modulation ################################################################################
     7090#### Plot Modulation ################################################################################
    70917091def ModulationPlot(G2frame,data,atom,ax,off=0):
    70927092    'Needs a description'
     
    72017201    Page.canvas.draw()
    72027202   
    7203 ##### PlotCovariance ################################################################################
     7203#### PlotCovariance ################################################################################
    72047204def PlotCovariance(G2frame,Data):
    72057205    '''Plots the covariance matrix. Also shows values for parameters
     
    73147314    Page.canvas.draw()
    73157315   
    7316 ##### PlotTorsion ################################################################################
     7316#### PlotTorsion ################################################################################
    73177317def PlotTorsion(G2frame,phaseName,Torsion,TorName,Names=[],Angles=[],Coeff=[]):
    73187318    'needs a doc string'
     
    73737373    Page.canvas.draw()
    73747374   
    7375 ##### PlotRama ################################################################################
     7375#### PlotRama ################################################################################
    73767376def PlotRama(G2frame,phaseName,Rama,RamaName,Names=[],PhiPsi=[],Coeff=[]):
    73777377    'needs a doc string'
     
    74667466
    74677467
    7468 ##### PlotSeq ################################################################################
     7468#### PlotSeq ################################################################################
    74697469def PlotSelectedSequence(G2frame,ColumnList,TableGet,SelectX,fitnum=None,fitvals=None):
    74707470    '''Plot a result from a sequential refinement
     
    75997599    SeqDraw()
    76007600               
    7601 ##### PlotExposedImage & PlotImage ################################################################################
     7601#### PlotExposedImage & PlotImage ################################################################################
    76027602def PlotExposedImage(G2frame,newPlot=False,event=None):
    76037603    '''General access module for 2D image plotting
     
    84798479        # try:
    84808480        Plot1,Plot = Page.figure.subplots(1,2,gridspec_kw=GS_kw)
    8481         # except AttributeError: # figure.Figure.subplots added in MPL 2.2
    8482         #     Plot1,Plot = MPLsubplots(Page.figure, 1,2, gridspec_kw=GS_kw)
    84838481        Plot1.set_title('Line scan at azm= %6.1f'%Data['linescan'][1])
    84848482        Plot1.set_xlabel(r'$\mathsf{2\Theta}$',fontsize=12)
     
    87618759        wx.EndBusyCursor()
    87628760   
    8763 ##### PlotIntegration ################################################################################
     8761#### PlotIntegration ################################################################################
    87648762def PlotIntegration(G2frame,newPlot=False,event=None):
    87658763    '''Plot of 2D image after image integration with 2-theta and azimuth as coordinates
     
    88138811        Page.canvas.draw()
    88148812               
    8815 ##### PlotRawImage ################################################################################
     8813#### PlotRawImage ################################################################################
    88168814def PlotRawImage(G2frame,image,label,newPlot=False):
    88178815    '''Plot an image without axes etc.
     
    88248822    Page.canvas.draw()
    88258823   
    8826 ##### PlotTRImage ################################################################################
     8824#### PlotTRImage ################################################################################
    88278825def PlotTRImage(G2frame,tax,tay,taz,newPlot=False):
    88288826    '''a test plot routine - not normally used
     
    88888886        Page.canvas.draw()
    88898887       
    8890 ##### PlotStructure ################################################################################
     8888#### PlotStructure ################################################################################
    88918889def PlotStructure(G2frame,data,firstCall=False,pageCallback=None):
    88928890    '''Crystal structure plotting package. Can show structures as balls, sticks, lines,
     
    1156711565    Page.canvas.SetCurrent(Page.context)
    1156811566    wx.CallAfter(Draw,'main')
    11569 
     11567   
     11568#### Plot Cluster Analysis ####################################################
     11569
     11570def PlotDendogram(G2frame,CLuDict,CLuZ,newPlot=True):
     11571   
     11572    import scipy.cluster.hierarchy as SCH
     11573    global Plot
     11574    def OnMotion(event):
     11575        xpos = event.xdata
     11576        if xpos:                                        #avoid out of frame mouse position
     11577            ypos = event.ydata
     11578            SetCursor(Page)
     11579            try:
     11580                G2frame.G2plotNB.status.SetStatusText('X =%9.3f %s =%9.3g'%(xpos,Title,ypos),1)                   
     11581            except TypeError:
     11582                G2frame.G2plotNB.status.SetStatusText('Select '+Title+' pattern first',1)
     11583    xylim = []
     11584    Title = 'Cluster dendogram'
     11585    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(Title,'mpl')
     11586    if not new:
     11587        if not newPlot:
     11588            xylim = copy.copy(lim)
     11589    else:
     11590        newPlot = True
     11591        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     11592   
     11593    Page.Choice = None
     11594    G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar
     11595    Plot.set_title('%s %s'%(CLuDict['LinkMethod'],Title))
     11596    Plot.set_xlabel(r''+CLuDict['Method']+' distance',fontsize=14)
     11597    Plot.set_ylabel(r''+'data set no.',fontsize=14)
     11598   
     11599    CLR = SCH.dendrogram(CLuZ,orientation='right',ax=Plot)
     11600
     11601    if not newPlot:
     11602        Page.toolbar.push_current()
     11603        Plot.set_xlim(xylim[0])
     11604        Plot.set_ylim(xylim[1])
     11605        Page.toolbar.push_current()
     11606        Page.ToolBarDraw()
     11607    else:
     11608        Page.canvas.draw()
     11609
     11610def PlotClusterXYZ(G2frame,YM,XYZ,CLuDict,Title='',PlotName=None):
     11611    ''' To plot cluster vectors
     11612    :param wx.Frame G2frame: The main GSAS-II tree "window"
     11613    :param array whitMat: whitened data matrix
     11614    :param array codebook: array of cluster centers
     11615   
     11616    :param str labelX,labelY,labelZ: labels for X,Y,Z-axes
     11617    :param str Title: plot title
     11618    :param str PlotName: plot tab name
     11619    '''
     11620    import scipy.cluster.hierarchy as SCH
     11621    from mpl_toolkits.axes_grid1.inset_locator import inset_axes   
     11622    def OnMotion(event):
     11623       
     11624        if event.xdata and event.ydata:       
     11625            G2frame.G2plotNB.status.SetStatusText('x=%.3f y=%.3f'%(event.xdata,event.ydata),1)
     11626           
     11627    def OnPick(event):
     11628        ind = event.ind
     11629        print(CLuDict['Files'][ind[0]])
     11630   
     11631    Colors = ['xkcd:blue','xkcd:red','xkcd:green','xkcd:cyan','xkcd:magenta','xkcd:black',
     11632        'xkcd:pink','xkcd:brown','xkcd:teal','xkcd:orange','xkcd:grey','xkcd:violet',]
     11633    G2frame.G2plotNB.Delete(PlotName)       #A cluge: to avoid AccessExceptions on replot
     11634    new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab(PlotName,'mpl')
     11635    Plot.set_visible(False)         #hide old plot frame, will get replaced below
     11636    if new:
     11637        Page.canvas.mpl_connect('motion_notify_event', OnMotion)
     11638        Page.canvas.mpl_connect('pick_event', OnPick)
     11639    G2frame.G2plotNB.status.SetStatusText('',1)
     11640    Page.Choice = None
     11641    np.seterr(all='ignore')
     11642       
     11643    Imin = np.min(YM)
     11644    Imax = np.max(YM)           
     11645    if CLuDict['CLuZ'] is not None:
     11646        gs = mpl.gridspec.GridSpec(2,2,figure=Page.figure)
     11647        ax1 = Page.figure.add_subplot(gs[0,0])
     11648        ax2 = Page.figure.add_subplot(gs[1,1],projection='3d')
     11649        ax3 = Page.figure.add_subplot(gs[0,1])
     11650        ax4 = Page.figure.add_subplot(gs[1,0])
     11651    else:
     11652        ax1 = Page.figure.add_subplot(211)
     11653        ax2 = Page.figure.add_subplot(212,projection='3d')
     11654        Page.figure.tight_layout()
     11655    Page.ImgObj = ax1.imshow(YM,interpolation='nearest',vmin=Imin,vmax=Imax,origin='lower')
     11656    cax = inset_axes(ax1,width="5%",height="100%",loc='lower left',bbox_to_anchor=(1.05, 0., 1, 1),
     11657        bbox_transform=ax1.transAxes,borderpad=0)
     11658    Page.figure.colorbar(Page.ImgObj, cax=cax)
     11659    if CLuDict['codes'] is not None:
     11660        ax2.scatter(XYZ[0],XYZ[1],XYZ[2],color=[Colors[code] for code in CLuDict['codes']],picker=True)
     11661    else:
     11662        ax2.scatter(XYZ[0],XYZ[1],XYZ[2],color=Colors[0],picker=True)
     11663    ax1.set_title(Title+' distances')
     11664    ax1.set_xlabel('Data set',fontsize=12)
     11665    ax1.set_ylabel('Data set',fontsize=12)
     11666    ax2.set_xlabel('PCA axis-1',fontsize=12)
     11667    ax2.set_ylabel('PCA axis-2',fontsize=12)
     11668    ax2.set_zlabel('PCA axis-3',fontsize=12)
     11669    if CLuDict['CLuZ'] is not None:
     11670        CLR = SCH.dendrogram(CLuDict['CLuZ'],orientation='right',ax=ax3)
     11671        ax3.set_title('%s %s'%(CLuDict['LinkMethod'],Title))
     11672        ax3.set_xlabel(r''+'data set no.',fontsize=12)
     11673        ax3.set_ylabel(r''+CLuDict['Method']+' distance',fontsize=12)
     11674        ax4.plot(100.*CLuDict['PCA'][:10]/np.sum(CLuDict['PCA']))
     11675        ax4.set_xlabel('PCA index',fontsize=12)
     11676        ax4.set_ylabel('% of total',fontsize=12)
     11677    Page.canvas.draw()
     11678       
Note: See TracChangeset for help on using the changeset viewer.