Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Last active February 19, 2025 02:56
Show Gist options
  • Save ProfAvery/7831c1e915c85e36b2f1486de2747bc6 to your computer and use it in GitHub Desktop.
Save ProfAvery/7831c1e915c85e36b2f1486de2747bc6 to your computer and use it in GitHub Desktop.
CPSC 375 - Monkey patch Lets-Plot to render graphs correctly as PDF
# This goes after the call to LetsPlot.setup_html(),
# but before calling ggplot().
def setup_svg():
def _repr_svg_(self):
from io import BytesIO
from sys import stdout
file_like = BytesIO()
self.to_svg(file_like)
return file_like.getvalue().decode(stdout.encoding)
import lets_plot
lets_plot.plot.core.PlotSpec._repr_svg_ = _repr_svg_
setup_svg()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment