mtopic.pl.corr_heatmap#
- mtopic.pl.corr_heatmap(arr1, arr2, label1=None, label2=None, cmap='bwr', fontsize=8, figsize=(8, 6), transparent=False, save=None)#
Visualize the correlation matrix between two sets of features as a heatmap.
This function computes and plots a correlation heatmap to visualize the relationships between two sets of features. Each set is represented as a pandas.DataFrame, with columns as features. The color intensity in the heatmap indicates the strength and direction of the correlation.
- Parameters:
arr1 (pandas.DataFrame) – A pandas DataFrame representing the first set of features. Each column corresponds to a feature.
arr2 (pandas.DataFrame) – A pandas DataFrame representing the second set of features. Each column corresponds to a feature.
label1 (str, optional) – Label for the y-axis, representing the features from arr1. If None, no label is set. Default is None.
label2 (str, optional) – Label for the x-axis, representing the features from arr2. If None, no label is set. Default is None.
cmap (str, optional) – Colormap for the heatmap. Default is ‘bwr’ (blue-white-red colormap).
fontsize (int, optional) – Font size for axis labels and colorbar ticks. Default is 8.
figsize (tuple, optional) – Tuple specifying the figure size (width, height) in inches. Default is (8, 6).
transparent (bool, optional) – If True, saves the figure with a transparent background. Default is False.
save (str, optional) – File path to save the figure. If None, the figure is displayed but not saved. Default is None.
- Returns:
None
- Example:
import pandas as pd import mtopic # Create example datasets data1 = pd.DataFrame({'feature1': [1, 2, 3], 'feature2': [4, 5, 6]}) data2 = pd.DataFrame({'feature3': [7, 8, 9], 'feature4': [10, 11, 12]}) # Plot correlation heatmap mtopic.pl.corr_heatmap( data1, data2, label1='Set 1', label2='Set 2', cmap='coolwarm', fontsize=10, save='correlation_heatmap.png' )