Skip to content

Commit

Permalink
feat: pick up matplotlib and seaborn fmt towards maidr
Browse files Browse the repository at this point in the history
  • Loading branch information
dakshpokar committed Aug 25, 2024
1 parent 20785a8 commit 4aa85be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 2 additions & 1 deletion maidr/core/plot/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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]
6 changes: 5 additions & 1 deletion maidr/patch/heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4aa85be

Please sign in to comment.