From fb5dde0c7b2d65f6649342ff5474f032e4e36bae Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Mon, 26 Aug 2024 23:52:32 -0500 Subject: [PATCH] feat: pick up seaborn heatmap fmt towards maidr (#90) --- maidr/core/plot/heatmap.py | 3 ++- maidr/patch/heatmap.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/maidr/core/plot/heatmap.py b/maidr/core/plot/heatmap.py index ba946a0..465673f 100644 --- a/maidr/core/plot/heatmap.py +++ b/maidr/core/plot/heatmap.py @@ -21,6 +21,7 @@ class HeatPlot( ): def __init__(self, ax: Axes, **kwargs) -> None: self._fill_label = kwargs.pop("fill_label") + self._fmt = kwargs.pop("fmt") super().__init__(ax, PlotType.HEAT) def render(self) -> dict: @@ -71,4 +72,4 @@ def _extract_scalar_mappable_data( else: self._support_highlighting = False - return [list(map(float, row)) for row in array] + return [list(map(lambda x: float(format(x, self._fmt)), row)) for row in array] diff --git a/maidr/patch/heatmap.py b/maidr/patch/heatmap.py index 5bca950..9a6f188 100644 --- a/maidr/patch/heatmap.py +++ b/maidr/patch/heatmap.py @@ -12,13 +12,14 @@ def heat(wrapped, _, args, kwargs) -> Axes | AxesImage: # Check for additional label used by MAIDR heatmap. fill_label = kwargs.pop("fill_label", "Fill") + fmt = kwargs.get("fmt", "") # Patch `ax.imshow()` and `seaborn.heatmap`. plot = wrapped(*args, **kwargs) # Extract the heatmap data points for MAIDR from the plots. ax = FigureManager.get_axes(plot) - FigureManager.create_maidr(ax, PlotType.HEAT, fill_label=fill_label) + FigureManager.create_maidr(ax, PlotType.HEAT, fill_label=fill_label, fmt=fmt) # Return to the caller. return plot