dsci_524_ezplot.plot_heatmap

Functions

plot_heatmap(data[, title, cmap, xlabel, ylabel])

Create a heatmap using a pandas DataFrame or a 2D NumPy array.

Module Contents

dsci_524_ezplot.plot_heatmap.plot_heatmap(data, title=None, cmap='viridis', xlabel=None, ylabel=None)[source]

Create a heatmap using a pandas DataFrame or a 2D NumPy array.

Parameters:
  • data (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; non-numeric values will cause errors.

  • title (str, optional) – Title of the heatmap. Default is None.

  • 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 is not a pandas DataFrame or a NumPy array.

  • ValueError – If the input data is empty or contains non-numeric values.

Examples

Using a pandas DataFrame: >>> 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”)

Using a NumPy array: >>> arr = np.random.rand(5, 5) >>> fig, ax = plot_heatmap(arr, title=”Heatmap from NumPy array”)