Belle II Software development
CorrelationMatrix Class Reference
Inheritance diagram for CorrelationMatrix:
Plotter

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 1245 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 1256 of file plotting.py.

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

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 1280 of file plotting.py.

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

◆ finish()

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

Reimplemented from Plotter.

Definition at line 1343 of file plotting.py.

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

Member Data Documentation

◆ axis

axis

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

Definition at line 1276 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 1254 of file plotting.py.

◆ bckgrd_axis [2/2]

bckgrd_axis

add background subplot

Definition at line 1272 of file plotting.py.

◆ colorbar_axis

colorbar_axis

Colorbar axis contains the colorbar.

Definition at line 1274 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1250 of file plotting.py.

◆ figure [2/2]

figure

create figure

Definition at line 1263 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 1252 of file plotting.py.

◆ signal_axis [2/2]

signal_axis

add signal subplot

Definition at line 1270 of file plotting.py.


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