Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-migas committed Sep 18, 2024
1 parent f7e490e commit 76000b4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/koyo/pdf_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ def _save_pdf(self, pdf: PdfPages, reset: bool = False) -> None:
"""Save PPTX."""
if pdf and hasattr(pdf, "close"):
pdf.close()
filename = self.pdf_filename
if pdf and hasattr(pdf, "filename"):
filename = Path(pdf.filename)
logger.debug(f"Saved PDF to {self.pdf_filename}")
if reset:
self._pdf = None
Expand Down
4 changes: 2 additions & 2 deletions src/koyo/pptx_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _export_pptx_figures(self, filename: PathLike | None = None) -> ty.Generator
try:
yield pptx
except Exception as e:
logger.error(f"Error exporting to PPTX: {e}")
logger.exception(f"Error exporting to PPTX: {e}")
finally:
if self.as_pptx:
self._save_pptx(pptx, filename, reset) # type: ignore[arg-type]
Expand Down Expand Up @@ -161,7 +161,7 @@ def _save_pptx(self, pptx: Presentation, filename: PathLike | None = None, reset
else:
filename = filename or self.pptx_filename
pptx.save(filename) # type: ignore[arg-type]
logger.trace(f"Saved PPTX to {filename}")
logger.trace(f"Saved PPTX to {filename} with {len(pptx.slides)} slides")
if reset:
self._pptx = None

Expand Down
15 changes: 13 additions & 2 deletions src/koyo/visuals.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from PIL import Image
from matplotlib.colorbar import Colorbar
from matplotlib.image import AxesImage
from seaborn.matrix import _HeatMapper

MATPLOTLIB_ABOVE_3_5_2 = is_above_version("matplotlib", "3.5.2")

Expand Down Expand Up @@ -488,13 +489,23 @@ def fix_style(style: str) -> str:
return style


def _annotate_heatmap(g, ax, mesh):
def _override_seaborn_heatmap_annotations():
from seaborn.matrix import _HeatMapper

if not hasattr(_HeatMapper, "_annotate_heatmap_old"):
_HeatMapper._annotate_heatmap_old = _HeatMapper._annotate_heatmap
_HeatMapper._annotate_heatmap = _annotate_heatmap


def _annotate_heatmap(g: _HeatMapper, ax: plt.Axes, mesh) -> None:
from seaborn.utils import relative_luminance

mesh.update_scalarmappable()
height, width = g.annot_data.shape
xpos, ypos = np.meshgrid(np.arange(width) + 0.5, np.arange(height) + 0.5)
for x, y, m, color, val in zip(xpos.flat, ypos.flat, mesh.get_array(), mesh.get_facecolors(), g.annot_data.flat):
for x, y, m, color, val in zip(
xpos.flat, ypos.flat, mesh.get_array().flat, mesh.get_facecolors(), g.annot_data.flat
):
if m is not np.ma.masked:
lum = relative_luminance(color)
text_color = ".15" if lum > 0.408 else "w"
Expand Down

0 comments on commit 76000b4

Please sign in to comment.