Belle II Software light-2406-ragdoll
CorrelationMatrix Class Reference
Inheritance diagram for CorrelationMatrix:
Collaboration diagram for CorrelationMatrix:

Public Member Functions

def __init__ (self, figure=None)
 
def add (self, data, columns, signal_mask, bckgrd_mask)
 
def finish (self)
 

Public Attributes

 figure
 create figure
 
 signal_axis
 add signal subplot
 
 bckgrd_axis
 add background subplot
 
 colorbar_axis
 Colorbar axis contains the colorbar.
 
 axis
 Usual axis object which every Plotter object needs, here it is just a dummy.
 

Static Public Attributes

None figure = None
 figure which is used to draw
 
None signal_axis = None
 Main axis which shows the correlation of the signal samples.
 
None bckgrd_axis = None
 Axis which shows the correlation of the background samples.
 

Detailed Description

Plots correlation matrix

Definition at line 1242 of file plotting.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  figure = None 
)
Creates a new figure if None is given, sets the default plot parameters
@param figure default draw figure which is used

Reimplemented from Plotter.

Definition at line 1253 of file plotting.py.

1253 def __init__(self, figure=None):
1254 """
1255 Creates a new figure if None is given, sets the default plot parameters
1256 @param figure default draw figure which is used
1257 """
1258 if figure is None:
1259
1260 self.figure = matplotlib.figure.Figure(figsize=(32, 18))
1261 self.figure.set_tight_layout(True)
1262 else:
1263 self.figure = figure
1264
1265 gs = matplotlib.gridspec.GridSpec(8, 2)
1266
1267 self.signal_axis = self.figure.add_subplot(gs[:6, 0])
1268
1269 self.bckgrd_axis = self.figure.add_subplot(gs[:6, 1], sharey=self.signal_axis)
1270
1271 self.colorbar_axis = self.figure.add_subplot(gs[7, :])
1272
1273 self.axis = self.signal_axis
1274
1275 super().__init__(self.figure, self.axis)
1276

Member Function Documentation

◆ add()

def add (   self,
  data,
  columns,
  signal_mask,
  bckgrd_mask 
)
Add a new correlation plot.
@param data pandas.DataFrame containing all data
@param columns which are used to calculate the correlations

Reimplemented from Plotter.

Definition at line 1277 of file plotting.py.

1277 def add(self, data, columns, signal_mask, bckgrd_mask):
1278 """
1279 Add a new correlation plot.
1280 @param data pandas.DataFrame containing all data
1281 @param columns which are used to calculate the correlations
1282 """
1283 signal_corr = numpy.corrcoef(numpy.vstack([data[column][signal_mask] for column in columns])) * 100
1284 bckgrd_corr = numpy.corrcoef(numpy.vstack([data[column][bckgrd_mask] for column in columns])) * 100
1285
1286 signal_heatmap = self.signal_axis.pcolor(signal_corr, cmap=plt.cm.RdBu, vmin=-100.0, vmax=100.0)
1287 self.bckgrd_axis.pcolor(bckgrd_corr, cmap=plt.cm.RdBu, vmin=-100.0, vmax=100.0)
1288
1289 self.signal_axis.invert_yaxis()
1290 self.signal_axis.xaxis.tick_top()
1291 self.bckgrd_axis.invert_yaxis()
1292 self.bckgrd_axis.xaxis.tick_top()
1293
1294 # put the major ticks at the middle of each cell
1295 self.signal_axis.set_xticks(numpy.arange(signal_corr.shape[0]) + 0.5, minor=False)
1296 self.signal_axis.set_yticks(numpy.arange(signal_corr.shape[1]) + 0.5, minor=False)
1297
1298 self.signal_axis.set_xticklabels(columns, minor=False, rotation=90)
1299 self.signal_axis.set_yticklabels(columns, minor=False)
1300
1301 # put the major ticks at the middle of each cell
1302 self.bckgrd_axis.set_xticks(numpy.arange(bckgrd_corr.shape[0]) + 0.5, minor=False)
1303 self.bckgrd_axis.set_yticks(numpy.arange(bckgrd_corr.shape[1]) + 0.5, minor=False)
1304
1305 self.bckgrd_axis.set_xticklabels(columns, minor=False, rotation=90)
1306 self.bckgrd_axis.set_yticklabels(columns, minor=False)
1307
1308 for y in range(signal_corr.shape[0]):
1309 for x in range(signal_corr.shape[1]):
1310 txt = self.signal_axis.text(x + 0.5, y + 0.5, f'{signal_corr[y, x]:.0f}',
1311 size=14,
1312 horizontalalignment='center',
1313 verticalalignment='center',
1314 color='w')
1315 txt.set_path_effects([PathEffects.withStroke(linewidth=3, foreground='k')])
1316
1317 for y in range(bckgrd_corr.shape[0]):
1318 for x in range(bckgrd_corr.shape[1]):
1319 txt = self.bckgrd_axis.text(x + 0.5, y + 0.5, f'{bckgrd_corr[y, x]:.0f}',
1320 size=14,
1321 horizontalalignment='center',
1322 verticalalignment='center',
1323 color='w')
1324 txt.set_path_effects([PathEffects.withStroke(linewidth=3, foreground='k')])
1325
1326 cb = self.figure.colorbar(signal_heatmap, cax=self.colorbar_axis, ticks=[-100, 0, 100], orientation='horizontal')
1327 cb.solids.set_rasterized(True)
1328 cb.ax.set_xticklabels(['negative', 'uncorrelated', 'positive'])
1329
1330 self.signal_axis.text(0.5, -1.0, "Signal", horizontalalignment='center')
1331 self.bckgrd_axis.text(0.5, -1.0, "Background", horizontalalignment='center')
1332
1333 # remove whitespace
1334 self.signal_axis.set_xlim(0, signal_corr.shape[0])
1335 self.signal_axis.set_ylim(0, signal_corr.shape[1])
1336 self.bckgrd_axis.set_xlim(0, bckgrd_corr.shape[0])
1337 self.bckgrd_axis.set_ylim(0, bckgrd_corr.shape[1])
1338 return self
1339

◆ finish()

def finish (   self)
Sets limits, title, axis-labels and legend of the plot

Reimplemented from Plotter.

Definition at line 1340 of file plotting.py.

1340 def finish(self):
1341 """
1342 Sets limits, title, axis-labels and legend of the plot
1343 """
1344 matplotlib.artist.setp(self.bckgrd_axis.get_yticklabels(), visible=False)
1345 return self
1346
1347

Member Data Documentation

◆ axis

axis

Usual axis object which every Plotter object needs, here it is just a dummy.

Definition at line 1273 of file plotting.py.

◆ bckgrd_axis [1/2]

None bckgrd_axis = None
static

Axis which shows the correlation of the background samples.

Definition at line 1251 of file plotting.py.

◆ bckgrd_axis [2/2]

bckgrd_axis

add background subplot

Definition at line 1269 of file plotting.py.

◆ colorbar_axis

colorbar_axis

Colorbar axis contains the colorbar.

Definition at line 1271 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1247 of file plotting.py.

◆ figure [2/2]

figure

create figure

Definition at line 1260 of file plotting.py.

◆ signal_axis [1/2]

None signal_axis = None
static

Main axis which shows the correlation of the signal samples.

Definition at line 1249 of file plotting.py.

◆ signal_axis [2/2]

signal_axis

add signal subplot

Definition at line 1267 of file plotting.py.


The documentation for this class was generated from the following file: