Skip to content

Instantly share code, notes, and snippets.

@ProfAvery
Last active October 8, 2024 17:41
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 correctly in Colab2PDF
# This goes after the call to LetsPlot.setup_html(),
# but before calling ggplot().
def setup_colab2pdf():
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_colab2pdf()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment