Live data from Hacker News

Tips and tricks to write LaTeX papers in with figures generated in Python

github.com

1–10 of 68 posts

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#2
This is probably most useful for postgrad students getting started with writing with TeX.

It’s worth pointing out that the figures are made using the matplotlib library, which is primarily based on Matlab’s plotting functionality. This is perhaps just as useful for new researchers as many of them are taught Matlab exclusively throughout their undergraduate courses.

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#3
> We also recommend to save the command used to generate a figure in the LaTeX file

An approach I have adopted recently is Knitr[1], so this layer of indirection goes away. With knitr, my data goes directly into the paper repository, and then my Makefile has something like this:

  %.tex: graphs/%.Rnw
    Rscript -e "library(knitr); knit('$?')"
The nice thing is exactly what the authors recommend: it's much easier to enforce a standard appearance across all the figures, and automatically incorporate more recent data into the paper as part of the compilation process.

[1] https://yihui.name/knitr/

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#4
Thanks for the write-up! Two notes from my experience: pgf output works well with latex as well (although will slowdown compilation), and I recommend not using the pyplot submodule, especially if you'll be running things remotely over ssh and don't have a display

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#5
post #4

Thanks for the write-up! Two notes from my experience: pgf output works well with latex as well (although will slowdown compilation), and I recommend not using the pyplot submodule, especially if you'll be running things remotely over ssh and don't have a display

Would you suggest an alternative to pyplot? What problems does it cause for you?

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#7
post #6

Meta: there seems to be an extra "in" in the title, that makes no sense to me, at least. Not a native speaker, though.

It's a careless transposition of "papers in LaTeX" → "LaTeX papers in" without removing the "in".

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#8
post #4

Thanks for the write-up! Two notes from my experience: pgf output works well with latex as well (although will slowdown compilation), and I recommend not using the pyplot submodule, especially if you'll be running things remotely over ssh and don't have a display

Would you suggest an alternative to pyplot? What problems does it cause for you?

I had problems using pyplot over ssh because it can assume there's a display and fail when it couldn't find one. Maybe this has changed. I use the OO interface. For example https://matplotlib.org/gallery/api/agg_oo_sgskip.html

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#9
I also recommend separating repetitive parts of plot generating code into template files, such as with mako or jinja2, and then programmatically generate sequences of plots by first piping the data into the jinja2 template, and then using insert commands to insert it into a bigger tex document.

I found this helpful when writing a paper where the appendix needed over 35 different tables of regression results, all with the same format but populated with data from different subpopulations, which would need to be regenerated (including updated captions, etc.) any time data cleaning or methodology was changed.

Re: Tips and tricks to write LaTeX papers in with figures generated in Python

#10
One itch which (curiously) I can't seem to quite scratch in LaTeX is that it should be possible to say "plot equation \ref{eq:smth} for X in (-4,4)" and just get the bloody graph. Why should I need to define the equation again in a separate place, perhaps even in a separate file?
Post reply on HN