From 39f407390368082648484ec2aef9ed0225a191fe Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Thu, 22 Aug 2024 11:21:57 -0500 Subject: [PATCH] feat: pick up matplotlib and seaborn fmt towards maidr --- maidr/core/plot/heatmap.py | 3 ++- maidr/patch/heatmap.py | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/maidr/core/plot/heatmap.py b/maidr/core/plot/heatmap.py index ba946a0..88dbeee 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", ".2f") 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..9fde774 100644 --- a/maidr/patch/heatmap.py +++ b/maidr/patch/heatmap.py @@ -13,12 +13,16 @@ def heat(wrapped, _, args, kwargs) -> Axes | AxesImage: # Check for additional label used by MAIDR heatmap. fill_label = kwargs.pop("fill_label", "Fill") + _fmt = ".2f" + if "fmt" in kwargs: + _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