Changeset 4003 for trunk/GSASIIplot.py
- Timestamp:
- May 29, 2019 6:22:27 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/GSASIIplot.py
r3999 r4003 6058 6058 6059 6059 def PlotCovariance(G2frame,Data): 6060 'needs a doc string' 6061 if not Data: 6062 print ('No covariance matrix available') 6063 return 6064 varyList = Data['varyList'] 6065 values = Data['variables'] 6066 covMatrix = Data['covMatrix'] 6067 sig = np.sqrt(np.diag(covMatrix)) 6068 xvar = np.outer(sig,np.ones_like(sig)) 6069 covArray = np.divide(np.divide(covMatrix,xvar),xvar.T) 6070 title = G2obj.StripUnicode(' for\n'+Data['title'],'') # matplotlib 1.x does not like unicode 6071 newAtomDict = Data.get('newAtomDict',{}) 6072 G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar 6073 6060 '''Plots the covariance matrix. Also shows values for parameters 6061 and their standard uncertainties (esd's) or the correlation between 6062 variables. 6063 ''' 6074 6064 def OnPlotKeyPress(event): 6075 6065 if event.key == 's': … … 6090 6080 covFile.write('*' + 126*' ' + '*\n') 6091 6081 covFile.write(128*'*' + '\n\n\n\n') 6092 llen = len( varyList)6082 llen = len(Page.varyList) 6093 6083 for start in range(0, llen, 8): # split matrix into batches of 7 columns 6094 6084 if llen >= start + 8: … … 6098 6088 covFile.write(12*' ' + '\t') 6099 6089 for idx in range(start, stop): 6100 covFile.write('{:^12}\t'.format( varyList[idx]))6090 covFile.write('{:^12}\t'.format(Page.varyList[idx])) 6101 6091 covFile.write('\n\n') 6102 6092 for line in range(llen): 6103 covFile.write('{:>12}\t'.format( varyList[line]))6093 covFile.write('{:>12}\t'.format(Page.varyList[line])) 6104 6094 for idx in range(start, stop): 6105 covFile.write('{: 12.6f}\t'.format( covArray[line][idx]))6095 covFile.write('{: 12.6f}\t'.format(Page.covArray[line][idx])) 6106 6096 covFile.write('\n') 6107 6097 covFile.write('\n\n\n') 6108 6098 covFile.close() 6109 PlotCovariance(G2frame,Data)6099 wx.CallAfter(PlotCovariance,G2frame,Data) 6110 6100 6111 6101 def OnMotion(event): 6112 6102 if event.button: 6113 6103 ytics = imgAx.get_yticks() 6114 ytics = np.where(ytics<len( varyList),ytics,-1)6115 ylabs = [np.where(0<=i , varyList[int(i)],' ') for i in ytics]6104 ytics = np.where(ytics<len(Page.varyList),ytics,-1) 6105 ylabs = [np.where(0<=i ,Page.varyList[int(i)],' ') for i in ytics] 6116 6106 imgAx.set_yticklabels(ylabs) 6117 6107 if event.xdata and event.ydata: #avoid out of frame errors 6118 6108 xpos = int(event.xdata+.5) 6119 6109 ypos = int(event.ydata+.5) 6120 if -1 < xpos < len( varyList) and -1 < ypos < len(varyList):6110 if -1 < xpos < len(Page.varyList) and -1 < ypos < len(Page.varyList): 6121 6111 if xpos == ypos: 6122 value = values[xpos]6123 name = varyList[xpos]6124 if varyList[xpos] innewAtomDict:6125 name,value = newAtomDict[name]6126 msg = '%s value = %.4g, esd = %.4g'%(name,value, sig[xpos])6112 value = Page.values[xpos] 6113 name = Page.varyList[xpos] 6114 if Page.varyList[xpos] in Page.newAtomDict: 6115 name,value = Page.newAtomDict[name] 6116 msg = '%s value = %.4g, esd = %.4g'%(name,value,Page.sig[xpos]) 6127 6117 else: 6128 msg = '%s - %s: %5.3f'%( varyList[xpos],varyList[ypos],covArray[xpos][ypos])6118 msg = '%s - %s: %5.3f'%(Page.varyList[xpos],Page.varyList[ypos],Page.covArray[xpos][ypos]) 6129 6119 Page.SetToolTipString(msg) 6130 6120 G2frame.G2plotNB.status.SetStatusText(msg,1) 6131 6121 6122 #==== PlotCovariance(G2frame,Data) starts here ========================= 6123 if not Data: 6124 print ('No covariance matrix available') 6125 return 6132 6126 new,plotNum,Page,Plot,lim = G2frame.G2plotNB.FindPlotTab('Covariance','mpl') 6133 6127 if not new: … … 6137 6131 Page.canvas.mpl_connect('motion_notify_event', OnMotion) 6138 6132 Page.canvas.mpl_connect('key_press_event', OnPlotKeyPress) 6133 Page.varyList = Data['varyList'] 6134 Page.values = Data['variables'] 6135 covMatrix = Data['covMatrix'] 6136 Page.sig = np.sqrt(np.diag(covMatrix)) 6137 xvar = np.outer(Page.sig,np.ones_like(Page.sig)) 6138 Page.covArray = np.divide(np.divide(covMatrix,xvar),xvar.T) 6139 title = G2obj.StripUnicode(' for\n'+Data['title'],'') # matplotlib 1.x does not like unicode 6140 Page.newAtomDict = Data.get('newAtomDict',{}) 6141 G2frame.G2plotNB.status.DestroyChildren() #get rid of special stuff on status bar 6139 6142 Page.Choice = ['s: to change colors','p: to save covariance as text file'] 6140 6143 Page.keyPress = OnPlotKeyPress … … 6143 6146 G2frame.G2plotNB.status.SetStatusWidths([150,-1]) #need to reset field widths here 6144 6147 acolor = mpl.cm.get_cmap(G2frame.VcovColor) 6145 Img = Plot.imshow( covArray,aspect='equal',cmap=acolor,interpolation='nearest',origin='lower',6148 Img = Plot.imshow(Page.covArray,aspect='equal',cmap=acolor,interpolation='nearest',origin='lower', 6146 6149 vmin=-1.,vmax=1.) 6147 6150 imgAx = Img.axes 6148 6151 ytics = imgAx.get_yticks() 6149 ylabs = [ varyList[int(i)] for i in ytics[:-1]]6152 ylabs = [Page.varyList[int(i)] for i in ytics[:-1]] 6150 6153 imgAx.set_yticklabels(ylabs) 6151 6154 Page.figure.colorbar(Img)
Note: See TracChangeset
for help on using the changeset viewer.