Last active
October 8, 2024 17:41
-
-
Save ProfAvery/7831c1e915c85e36b2f1486de2747bc6 to your computer and use it in GitHub Desktop.
CPSC 375 - Monkey patch Lets-Plot to render correctly in Colab2PDF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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