plot
eempy.plot.plot
Functions for plotting EEM-related data Author: Yongmin Hu (yongminhu@outlook.com) Last update: 2026-01
plot_abs
plot_abs(absorbance, ex_range, xmax=0.1, ex_range_display=(200, 800), plot_tool='matplotlib', display=True, figure_size=(6.5, 2))
Plot the UV absorbance data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
absorbance
|
np.ndarray
|
The absorbance spectrum (1D array). |
required |
ex_range
|
np.ndarray
|
The excitation wavelengths (1D array). |
required |
xmax
|
float (0~1)
|
The maximum absorbance displayed. |
0.1
|
ex_range_display
|
tuple with two elements
|
The range of excitation wavelengths displayed. |
(200, 800)
|
plot_tool
|
str, {'matplotlib', 'plotly'}
|
Which python package to use for plotting. |
'matplotlib'
|
display
|
bool
|
Whether to display the figure when calling the function. |
True
|
figure_size
|
tuple (width, height)
|
The size of the plot. |
(6.5, 2)
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
Axes object when |
plot_dendrogram
plot_dendrogram(linkage_matrix, threshold, index: Optional[list] = None)
Plot a dendrogram from a linkage matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
linkage_matrix
|
np.ndarray
|
Linkage matrix from hierarchical clustering. |
required |
threshold
|
float
|
Distance threshold for coloring clusters. |
required |
index
|
list or None
|
Optional labels for samples. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
plot_eem
plot_eem(intensity: ndarray, ex_range, em_range, auto_intensity_range=True, scale_type='linear', vmin=0, vmax=10000, n_cbar_ticks=5, cbar=True, cmap='jet', figure_size=(10, 7), axis_label_font_size=18, axis_ticks_font_size=16, cbar_label='Intensity (a.u.)', cbar_font_size=16, cbar_fraction=0.02, fix_aspect_ratio=True, rotate=False, plot_tool='matplotlib', display=True, title=None, title_font_size=20)
Plot EEM or EEM-like data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
intensity
|
np.ndarray
|
The EEM. |
required |
ex_range
|
np.ndarray
|
The excitation wavelengths. |
required |
em_range
|
np.ndarray
|
The emission wavelengths. |
required |
auto_intensity_range
|
bool
|
Whether to use the colorbar range generated automatically by matplotlib for plotting fluorescence intensity. |
True
|
scale_type
|
str, {'linear', 'log'}
|
The type of colorbar scale used for plotting fluorescence intensity. |
'linear'
|
vmin
|
int or float
|
The minimum intensity displayed, if you wish to adjust the intensity scale yourself (autoscale=False). |
0
|
vmax
|
int or float
|
The maximum intensity displayed, if you wish to adjust the intensity scale yourself (autoscale=False). |
10000
|
n_cbar_ticks
|
int
|
The number of ticks in colorbar. |
5
|
cmap
|
str
|
The colormap, see https://matplotlib.org/stable/users/explain/colors/colormaps.html. |
'jet'
|
figure_size
|
tuple or list with two elements
|
The figure size. |
(10, 7)
|
axis_label_font_size
|
int
|
The fontsize of the x and y axes labels. |
18
|
axis_ticks_font_size
|
int
|
The fontsize of the x and y ticks labels. |
16
|
cbar
|
bool
|
Whether to plot the colorscale bar. |
True
|
cbar_label
|
str
|
The label of the colorbar scale. |
'Intensity (a.u.)'
|
cbar_font_size
|
int
|
The label size of the colorbar scale. |
16
|
cbar_fraction
|
float
|
The size fraction of the colorbar scale. |
0.02
|
fix_aspect_ratio
|
bool
|
Whether to fix the aspect ratio to be one. |
True
|
rotate
|
bool
|
Whether to rotate the EEM, so that the x-axis is excitation and y-axis is emission. |
False
|
plot_tool
|
str, {'matplotlib', 'plotly'}
|
Which python package to use for plotting. |
'matplotlib'
|
display
|
bool
|
Whether to display the figure when calling the function |
True
|
title
|
str
|
Plot title. |
None
|
title_font_size
|
int
|
Font size for the plot title. |
20
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
Axes object when |
im |
AxesImage
|
Image handle when |
plot_eem_stack
plot_eem_stack(eem_stack: ndarray, ex_range: ndarray, em_range: ndarray, titles: Optional[list] = None, n_cols: int = 2, auto_intensity_range: bool = True, scale_type: str = 'linear', vmin: Optional[float] = None, vmax: Optional[float] = None, cmap: str = 'jet', figure_size: tuple = (12, 12), axis_label_font_size: int = 12, axis_ticks_font_size: int = 10, cbar: bool = True, cbar_fraction: float = 0.02, fix_aspect_ratio: bool = True, rotate: bool = False, suptitle: Optional[str] = None, suptitle_font_size: int = 16, plot_x_axis_label: bool = True, plot_y_axis_label: bool = True) -> tuple
Plot a stack of EEMs in a grid of subplots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
eem_stack
|
np.ndarray
|
Stack of EEMs, shape (n_samples, n_ex, n_em). |
required |
ex_range
|
np.ndarray
|
Excitation wavelengths (1D array). |
required |
em_range
|
np.ndarray
|
Emission wavelengths (1D array). |
required |
titles
|
list of str
|
List of subplot titles, length must equal number of EEMs. |
None
|
n_cols
|
int
|
Number of columns in the subplot grid. |
2
|
auto_intensity_range
|
bool
|
If True, use matplotlib's autoscale for intensities. |
True
|
scale_type
|
str
|
'linear' or 'log' scale for color mapping. |
'linear'
|
vmin
|
float
|
Minimum intensity if auto_intensity_range is False. |
None
|
vmax
|
float
|
Maximum intensity if auto_intensity_range is False. |
None
|
cmap
|
str
|
Matplotlib colormap. |
'jet'
|
figure_size
|
tuple
|
Size of the entire figure. |
(12, 12)
|
axis_label_font_size
|
int
|
Font size for axis labels. |
12
|
axis_ticks_font_size
|
int
|
Font size for axis ticks. |
10
|
cbar
|
bool
|
Whether to show a colorbar for each subplot. |
True
|
cbar_fraction
|
float
|
Fraction size of colorbar. |
0.02
|
fix_aspect_ratio
|
bool
|
If True, force aspect ratio to 1. |
True
|
rotate
|
bool
|
If True, swap axes so x=excitation and y=emission. |
False
|
suptitle
|
str
|
Overall figure title. |
None
|
suptitle_font_size
|
int
|
Font size for overall title. |
16
|
plot_x_axis_label
|
bool
|
Whether to show the x-axis label on each subplot. |
True
|
plot_y_axis_label
|
bool
|
Whether to show the y-axis label on each subplot. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
axes |
np.ndarray of Axes
|
|
ims |
list of AxesImage
|
|
plot_error
plot_error(error, bins='auto', display=True)
Plot a histogram of error values with sample indices on hover.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
error
|
pd.DataFrame
|
Error table with a single column. |
required |
bins
|
int, str, or sequence
|
Bin specification passed to NumPy histogram. |
'auto'
|
display
|
bool
|
Whether to display the figure when calling the function. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
plot_fi
plot_fi(fi: DataFrame, q: float = 0.05)
Plot the fluorescence intensities of samples at a specific pair of ex/em.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fi
|
pd.DataFrame
|
A DataFrame of shape (n,1), where n is the number of samples. The output of EEMDataset.peak_picking() can be passed to this parameter. |
required |
q
|
float
|
Where to plot the reference lines. By default, this is set to be 0.05 - two horizontal lines will be plotted at 95% and 105% of the average fluorescence intensity. |
0.05
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
|
plot_fi_correlation
plot_fi_correlation(fi: DataFrame, ref)
Plot fluorescence intensity versus the reference value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fi
|
pd.DataFrame
|
A DataFrame of shape (n,1), where n is the number of samples. The output of EEMDataset.peak_picking() can be passed to this parameter. |
required |
ref
|
np.ndarray
|
The reference values. It should be a 1D numpy array of shape (n,), where n is the number of samples. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
|
plot_fmax
plot_fmax(table, component_labels=None, display=True, yaxis_title='Fmax', labels=None)
Plot Fmax (or similar score) tables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
pd.DataFrame
|
Table of component scores (samples x components). |
required |
component_labels
|
list or None
|
Optional labels for components shown in the legend. |
None
|
display
|
bool
|
Whether to display the figure when calling the function. |
True
|
yaxis_title
|
str
|
Y-axis title for the score axis. |
'Fmax'
|
labels
|
array-like or None
|
Optional cluster labels used to overlay cluster-colored markers. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
plot_loadings
plot_loadings(parafac_models_dict: dict, colors=list(TABLEAU_COLORS.values()), component_labels_dict=None, n_cols=None, plot_tool='matplotlib', display=True, legend_pad=0)
Plot the excitation and emission loadings for PARAFAC models.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parafac_models_dict
|
dict
|
A dictionary of PARAFAC objects. Each PARAFAC model is labelled with a dictionary key. |
required |
colors
|
list
|
A list of matplotlib-compatible colors used for plotting. |
list(values())
|
component_labels_dict
|
dict or None
|
A dictionary of component names for each PARAFAC model. The keys of the dict should be identical to those of the parafac_models_dict. The value of each key is a list of component names. |
None
|
n_cols
|
int or None
|
Maximum number of subplots at each row. if None, subplots will be shown in-line. |
None
|
plot_tool
|
(str, {matplotlib, plotly})
|
Which python package to use for plotting. |
'matplotlib'
|
display
|
bool
|
Whether to display the figure when calling the function. |
True
|
legend_pad
|
float
|
Extra padding below the legend in the plotly layout. |
0
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|
ax |
Axes
|
Axes object when |
plot_reconstruction_error
plot_reconstruction_error(table, bar_col_name, display=True, yaxis_scatter_title='Reconstruction error', yaxis_bar_title='Reconstruction error reduction', labels=None)
Plot reconstruction errors and per-sample error reductions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
table
|
pd.DataFrame
|
Table containing error series. One column is used as bars (bar_col_name), the rest are plotted as lines. |
required |
bar_col_name
|
str
|
Column name used for the bar series. |
required |
display
|
bool
|
Whether to display the figure when calling the function. |
True
|
yaxis_scatter_title
|
str
|
Y-axis title for the line series. |
'Reconstruction error'
|
yaxis_bar_title
|
str
|
Y-axis title for the bar series. |
'Reconstruction error reduction'
|
labels
|
array-like or None
|
Optional cluster labels used to overlay cluster-colored markers and bars. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
fig |
Figure
|
|