plotting¶
analysis_helpers.plotting
¶
plot_hist(data, yerr=False, name=None, unit=None, ax=None, **kwargs)
¶
Plot a histogram from an array
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array
|
an array with the data to plot |
required |
yerr
|
bool
|
if True, plot the y error bars |
False
|
name
|
str
|
the variable name. Defaults to None. |
None
|
unit
|
str
|
the unit name. Defaults to None. |
None
|
ax
|
axis
|
matplotlib.axes object. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: matplotlib figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_hists(data_arrays, yerrs=False, name=None, unit=None, ax=None, **kwargs)
¶
Plot two histograms on the same axis using mplhep.histplot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_arrays
|
array<array>
|
Array with the data arrays for the each histogram. |
required |
yerrs
|
list<bool>
|
for each data set if True, plot y error bars for the relevant histogram. |
False
|
name
|
str
|
Name of the variable for the histograms. Defaults to None. |
None
|
unit
|
str
|
Unit name for the histograms. Defaults to None. |
None
|
ax
|
axis
|
Matplotlib axes object. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: Matplotlib figure and axis. |
Source code in src/analysis_helpers/plotting.py
plot_double_hist(data1, data2, yerr1=False, yerr2=False, name=None, unit=None, ax=None, **kwargs)
¶
Plot two histograms on the same axis using mplhep.histplot().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data1
|
array
|
Array with the data for the first histogram. |
required |
data2
|
array
|
Array with the data for the second histogram. |
required |
yerr1
|
bool
|
If True, plot y error bars for the first histogram. |
False
|
yerr2
|
bool
|
If True, plot y error bars for the second histogram. |
False
|
name1
|
str
|
Name of the variable for the first histogram. Defaults to None. |
required |
name2
|
str
|
Name of the variable for the second histogram. Defaults to None. |
required |
unit1
|
str
|
Unit name for the first histogram. Defaults to None. |
required |
unit2
|
str
|
Unit name for the second histogram. Defaults to None. |
required |
ax
|
axis
|
Matplotlib axes object. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: Matplotlib figure and axis. |
Source code in src/analysis_helpers/plotting.py
plot_significance_and_purity(metrics, values, sel_name=None, axs=None, **kwargs)
¶
Plots the significance and purity of a selection
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metrics
|
dict
|
a dictionary with significance and purity values |
required |
values
|
array
|
array of the selections |
required |
sel_name
|
str
|
the name of the selection. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, axs, ax2: matplotlib figure and axes |
Source code in src/analysis_helpers/plotting.py
plot_vertical_lines(ax, xline, color='red', linestyle='--')
¶
Plot vertical lines on an axis at specified values
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
axes
|
axis object where to plot the lines |
required |
xline
|
list
|
values of the x axis where to plot the lines |
required |
color
|
str
|
color of the lines. Defaults to 'red'. |
'red'
|
linestyle
|
str
|
style of the line. Defaults to '--'. |
'--'
|
Source code in src/analysis_helpers/plotting.py
plot_hist2d(x, y, ax=None, xlabel=None, ylabel=None, vmax=None, **kwargs)
¶
Plot and decorate a 2D histogram
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
the x values |
required |
y
|
array
|
the y values |
required |
ax
|
axis
|
the axis where to plot the histogram. Defaults to None. |
None
|
xlabel
|
str
|
x axis label. Defaults to None. |
None
|
ylabel
|
str
|
y axis label. Defaults to None. |
None
|
vmax
|
float
|
maximum value for the color scale. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_dalitz(m1, m2, xlab='', ylab='', masses=[], boundary=False, weights=None, log=False, logz=False, bininfo=False, ax=None, **kwargs)
¶
Draws a Dalitz plot of a three body decay.
Basically it is a 2d plotting function, but when the masses array is given (mother mass, mA, mB, mC), the boundary can also be shown.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
m1
|
_type_
|
description |
required |
m2
|
_type_
|
description |
required |
xlab
|
str
|
description. Defaults to ''. |
''
|
ylab
|
str
|
description. Defaults to ''. |
''
|
masses
|
list
|
description. Defaults to []. |
[]
|
boundary
|
bool
|
description. Defaults to False. |
False
|
weights
|
_type_
|
description. Defaults to None. |
None
|
log
|
bool
|
description. Defaults to False. |
False
|
logz
|
bool
|
description. Defaults to False. |
False
|
bininfo
|
bool
|
description. Defaults to False. |
False
|
ax
|
_type_
|
description. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
description |
ValueError
|
description |
Returns:
| Name | Type | Description |
|---|---|---|
_type_ |
description |
Source code in src/analysis_helpers/plotting.py
333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 | |
plot_removed(data, selection, selection_label=None, yerr=False, name=None, unit=None, ax=None, **kwargs)
¶
Plots the histogram of the data and the data that has been removed by the selection
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array
|
numpy array with the data |
required |
selection
|
array
|
numpy array with the selection |
required |
selection_label
|
str
|
the name of the selection for the legend. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: matplotlib figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_signal_and_backgrond_distributions(data, variable, metric_variable, signal_range, sidebands_ranges, ax=None, **kwargs)
¶
Plots signal and background distributions give the signal and sidebands ranges
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array
|
the numpy array with the data |
required |
variable
|
str
|
the name of the variable to plot |
required |
metric_variable
|
str
|
the name of the variable to cut on |
required |
signal_range
|
list
|
a list with the signal range |
required |
sidebands_ranges
|
array
|
a 2x2 list with the sidebands ranges |
required |
Returns:
| Type | Description |
|---|---|
|
fig, ax: matplotlib figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_efficiency(passed, total, name=None, unit=None, ax=None, **kwargs)
¶
Plots the efficiency distribution of two datasets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passed
|
array
|
array with the events that passed the selection |
required |
total
|
array
|
array with the total events in the sample |
required |
name
|
str
|
the variable name. Defaults to None. |
None
|
unit
|
str
|
the unit name. Defaults to None. |
None
|
ax
|
axis
|
axis of an already existing figure. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_efficiency2d(passed, total, xname=None, xunit=None, yname=None, yunit=None, ax=None, **kwargs)
¶
Plots the efficiency distribution of two datasets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passed
|
array
|
array with the events that passed the selection |
required |
total
|
array
|
array with the total events in the sample |
required |
name
|
str
|
the variable name. Defaults to None. |
required |
unit
|
str
|
the unit name. Defaults to None. |
required |
ax
|
axis
|
axis of an already existing figure. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: figure and axis |
Source code in src/analysis_helpers/plotting.py
plot_efficiency_with_distribution(passed, total, name=None, unit=None, ax=None, **kwargs)
¶
Plots the efficiency distribution of two datasets with the total distribution overlaid
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
passed
|
array
|
array with the events that passed the selection |
required |
total
|
array
|
array with the total events in the sample |
required |
name
|
str
|
the variable name. Defaults to None. |
None
|
unit
|
str
|
the unit name. Defaults to None. |
None
|
ax
|
axis
|
axis of an already existing figure. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, axs: figure and axes |
Source code in src/analysis_helpers/plotting.py
plot_asymmetry2d(arr1, arr2, xname=None, xunit=None, yname=None, yunit=None, ax=None, **kwargs)
¶
Plots the asymmetry between two datasets
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
arr1
|
array
|
array with the events from the first sample |
required |
arr2
|
array
|
array with the events from the second sample |
required |
xname
|
str
|
the variable on the x axis name. Defaults to None. |
None
|
xunit
|
str
|
the variable on the x axis unit name. Defaults to None. |
None
|
yname
|
str
|
the variable on the y axis name. Defaults to None. |
None
|
yunit
|
str
|
the variable on the y axis unit name. Defaults to None. |
None
|
ax
|
axis
|
axis of an already existing figure. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, ax: figure and axis |
Source code in src/analysis_helpers/plotting.py
create_subplots(num_plots, figsize=(10, 6))
¶
Creates a figure and axes for a given number of plots
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_plots
|
int
|
The total number of plots to create. |
required |
figsize
|
tuple
|
The size of the overall figure, specified as (width, height). Default is (10, 6). |
(10, 6)
|
Returns:
| Type | Description |
|---|---|
|
matplotlib.figure.Figure : The Matplotlib Figure object containing the subplots. |
|
|
list of matplotlib.axes._subplots.AxesSubplot : A flat list of Axes objects corresponding to the subplots. If the grid has more subplots than |
Example:
.. code-block:: python
>>> num_plots = 7
>>> fig, axes = create_subplots(num_plots)
>>> for i in range(num_plots):
>>> axes[i].plot([0, 1, 2], [i, i+1, i+2])
>>> axes[i].set_title(f"Plot {i+1}")
>>> plt.tight_layout()
>>> plt.show()
Source code in src/analysis_helpers/plotting.py
plot_2darray(data, xbins=None, ybins=None, zrange=None, xlabel='', ylabel='', colorbar_label='', title='', ax=None, lines=False)
¶
Plots a 2D array as a heatmap
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
array
|
the data to plot |
required |
xbins
|
array
|
binning on the x axis. Defaults to None. |
None
|
ybins
|
array
|
binning on the y axis. Defaults to None. |
None
|
zrange
|
tuple
|
z-axis range as (min,max). Defaults to None. |
None
|
colorbar_label
|
str
|
the color bar label. Defaults to ''. |
''
|
ax
|
axis
|
the axis where to make the plot. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
|
fig, axs: figure and axes |
Source code in src/analysis_helpers/plotting.py
configure_plot_layout(fig, method='tight_layout')
¶
Configure plot layout to prevent text overlapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fig
|
Figure
|
The matplotlib figure. |
required |
method
|
str
|
Layout method ('tight_layout', 'constrained', 'subplots_adjust'). |
'tight_layout'
|