From 6deed2760c9c71f2470bc080e06e073005b23a0f Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Thu, 22 Aug 2024 11:21:57 -0500 Subject: [PATCH 1/4] 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 From 1385fbc3df11f14cc6deca88f37eae12e4c40b1f Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Sun, 25 Aug 2024 23:46:04 -0500 Subject: [PATCH 2/4] fix: removed unnecessary print statements --- example/bar/example_bar_plot.ipynb | 1 - 1 file changed, 1 deletion(-) diff --git a/example/bar/example_bar_plot.ipynb b/example/bar/example_bar_plot.ipynb index a8bfb18..e0e4a37 100644 --- a/example/bar/example_bar_plot.ipynb +++ b/example/bar/example_bar_plot.ipynb @@ -45,7 +45,6 @@ "cut_counts = tips[\"day\"].value_counts()\n", "plt.figure(figsize=(10, 6))\n", "b_plot = plt.bar(cut_counts.index, list(cut_counts.values), color=\"skyblue\")\n", - "print(type(b_plot))\n", "plt.title(\"The Number of Tips by Day\")\n", "plt.xlabel(\"Day\")\n", "plt.ylabel(\"Count\")\n", From 002dd5cff9aa31e8edbc9005eb153facd4fc1656 Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Mon, 26 Aug 2024 15:56:39 -0500 Subject: [PATCH 3/4] Revert "fix: removed unnecessary print statements" This reverts commit c27fc4bfaa5516ecc4082cf617c5bc6beabc5d6f. --- example/bar/example_bar_plot.ipynb | 1 + 1 file changed, 1 insertion(+) diff --git a/example/bar/example_bar_plot.ipynb b/example/bar/example_bar_plot.ipynb index e0e4a37..a8bfb18 100644 --- a/example/bar/example_bar_plot.ipynb +++ b/example/bar/example_bar_plot.ipynb @@ -45,6 +45,7 @@ "cut_counts = tips[\"day\"].value_counts()\n", "plt.figure(figsize=(10, 6))\n", "b_plot = plt.bar(cut_counts.index, list(cut_counts.values), color=\"skyblue\")\n", + "print(type(b_plot))\n", "plt.title(\"The Number of Tips by Day\")\n", "plt.xlabel(\"Day\")\n", "plt.ylabel(\"Count\")\n", From 39a3bcd19acab2d086e931eb606d6b986c9a6140 Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Mon, 26 Aug 2024 23:40:47 -0500 Subject: [PATCH 4/4] fix: pr comments --- maidr/core/plot/heatmap.py | 2 +- maidr/patch/heatmap.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/maidr/core/plot/heatmap.py b/maidr/core/plot/heatmap.py index 88dbeee..465673f 100644 --- a/maidr/core/plot/heatmap.py +++ b/maidr/core/plot/heatmap.py @@ -21,7 +21,7 @@ class HeatPlot( ): def __init__(self, ax: Axes, **kwargs) -> None: self._fill_label = kwargs.pop("fill_label") - self._fmt = kwargs.pop("fmt", ".2f") + self._fmt = kwargs.pop("fmt") super().__init__(ax, PlotType.HEAT) def render(self) -> dict: diff --git a/maidr/patch/heatmap.py b/maidr/patch/heatmap.py index 9fde774..9a6f188 100644 --- a/maidr/patch/heatmap.py +++ b/maidr/patch/heatmap.py @@ -12,17 +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 = ".2f" - if "fmt" in kwargs: - _fmt = kwargs.get("fmt") + 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, fmt=_fmt) + FigureManager.create_maidr(ax, PlotType.HEAT, fill_label=fill_label, fmt=fmt) # Return to the caller. return plot