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

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

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

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

◆ finish()

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

Reimplemented from Plotter.

Definition at line 1341 of file plotting.py.

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

Member Data Documentation

◆ axis

axis

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

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

◆ bckgrd_axis [2/2]

bckgrd_axis

add background subplot

Definition at line 1270 of file plotting.py.

◆ colorbar_axis

colorbar_axis

Colorbar axis contains the colorbar.

Definition at line 1272 of file plotting.py.

◆ figure [1/2]

None figure = None
static

figure which is used to draw

Definition at line 1248 of file plotting.py.

◆ figure [2/2]

figure

create figure

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

◆ signal_axis [2/2]

signal_axis

add signal subplot

Definition at line 1268 of file plotting.py.


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