Live data from Hacker News

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

github.com

51–60 of 68 posts

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

#51

I have one tip for anyone using LaTeX: Please stop using the awful Computer Modern typeface.

Any typeface in particular that you do recommend?

Somewhat controversial, but I like it: Minion Pro :)

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

#52
I already implement most of the points mentioned there. The most useful (and new) tip for me was however the rasterization part. I normally like to have pdf figures for my LaTeX papers, but last time I had some graphics with some thousands of points plotted, which were taking too long to be printed if you did that from windows (in Linux there was no problem, that's why I didn't catch the problem earlier). At the end I decided to save the plot as png, but was not happy about it haha. It would have been good to know the rasterization trick earlier.

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

#53
If you are serious about making beautiful figures in latex, I would seriously recommend using tikz and pgf-plots. It is quite easy to automatically generate tikz-code from python (after all it is supposed to be read and written by humans) and all aspects of the figure can easily be customized. I have been quite successful in generating automated reports with pretty and easily readable figures using tikz and pgf.

If anyone is interested I have uploaded a sample script for generating XY-plots from two numpy lists to github. The code is by no means very good, but I just wanted to share in case anyone wants to try this approach.

https://github.com/sigurdjs/python-tikz

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

#55
post #37

I'd also add that for figures Inkscape is invaluable [1]. Save as svg once, and export it as whatever later. I typically export it to PDF (from within Inkscape) for pdflatex. While its typically indispensable for schematics, I often seem to run into the use case of combining previously generated plots or figures, or adding a label/text. Since Inkscape can import pngs, this is a breeze with it. I don't have to go back…

Have you considered plotly [1] as an alternative to matplotlib?

It is mostly known for online plots but it has a free offline API that can export plots to eps/pfd/png/etc.

Parts of their libraries are aimed for interactive plots but imo the basic plots look even better than those of seaborn.

[1] https://plot.ly/python/

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

#56

I have one tip for anyone using LaTeX: Please stop using the awful Computer Modern typeface.

I personally find Computer Modern quite pleasant to read and work with. Apart from personal preference, why avoid Computer Modern?

It is an extremely thin font which makes it unsuitable for screen reading.

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

#57

Is there a better and more comprehensive plotting library than Matplotlib, it's 3D plots a lack polish. Also it is kind of verbose and require much boilerplate. Its api is sprawling and hard to remember.

Check Seaborn, it may suit your needs.

https://seaborn.pydata.org/

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

#58

If you are serious about making beautiful figures in latex, I would seriously recommend using tikz and pgf-plots. It is quite easy to automatically generate tikz-code from python (after all it is supposed to be read and written by humans) and all aspects of the figure can easily be customized. I have been quite successful in generating automated reports with pretty and easily readable figures using tikz and pgf. If a…

And it's also possible to directly load a csv file with all the data in latex and plot if with pgf, which makes it possible to keep all the plotting options in the latex file:

  \addplot table[x ={Column1}, y ={Column2}] {myData.csv};
The issue is that it can take some time for pgf to load the data and do computations on them, but you can use the external library of tikz so that it does not compute the plot again (and save it as a pdf for later uses).

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

#59

Earlier quoted context omitted.

I personally find Computer Modern quite pleasant to read and work with. Apart from personal preference, why avoid Computer Modern?

It is an extremely thin font which makes it unsuitable for screen reading.

A lot of the time, the TeX output target is paper, and there (with a decent resolution printer) it looks rather splendid (in my view anyway).
Post reply on HN