dsci_524_ezplot.plot_heatmap
Functions
|
Create a heatmap using data from a pandas DataFrame or a 2D array. |
Module Contents
- dsci_524_ezplot.plot_heatmap.plot_heatmap(df, title=None, cmap='viridis', xlabel=None, ylabel=None)[source]
Create a heatmap using data from a pandas DataFrame or a 2D array.
- Parameters:
df (pandas.DataFrame or numpy.ndarray) – Input data for the heatmap. Can be a pandas DataFrame or a 2D NumPy array. The data should be numeric, as non-numeric values will cause errors.
title (str) – Title of the heatmap.
cmap (str, optional) – Colormap for the heatmap. Defaults to ‘viridis’.
xlabel (str, optional) – Label for the x-axis. Defaults to None.
ylabel (str, optional) – Label for the y-axis. Defaults to None.
- Returns:
- matplotlib.figure.Figure
The figure object containing the heatmap.
- matplotlib.axes.Axes
The axes object containing the heatmap elements.
- Return type:
tuple
- Raises:
TypeError – If the input data contains non-numeric values.
ValueError – If the input data is empty.
Examples
>>> import pandas as pd >>> import numpy as np >>> df = pd.DataFrame(np.random.rand(5, 5), columns=['A', 'B', 'C', 'D', 'E']) >>> fig, ax = plot_heatmap(df, title="Sample Heatmap", xlabel="Columns", ylabel="Rows")