Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
LaTeX, LLMs and Boring Technology (thegreenplace.net)
8 points by ibobev 5 months ago | hide | past | favorite | 1 comment


TikZ is definitely nice. For generating vector versions of your matplotlib plots, use FigureCanvasPgf.

https://matplotlib.org/stable/api/backend_pgf_api.html#matpl...

In Jupyter, that looks like

    !sudo apt-get -y install \
      texlive-xetex texlive-fonts-recommended texlive-plain-generic \
      texlive-latex-extra texlive-fonts-recommended dvipng cm-super \
      >/dev/null

    import matplotlib

    from matplotlib.backends.backend_pgf import FigureCanvasPgf
    matplotlib.backend_bases.register_backend('pdf', FigureCanvasPgf)

    import matplotlib.pyplot as plt
    from pdf2image import convert_from_path

    plt.rcParams.update({
        'font.family': 'serif',
        'font.serif': [],
        'font.size': 8,
        'text.usetex': True,
        'pgf.rcfonts': False,
    })
Using `convert_from_path` is for showing cached images.

Generate your figure with

    plt.savefig('foo.pdf', transparent=True)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: