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.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 to the original code to regenerate plots, or fiddle around with latex to make minor adjustments.
For stuff generated via matplotlib, I'd strongly recommend seaborn as an additional library [2]. This is a wrapper over matplotlib. It can prettify plots with just an import and a 'set' command. You can, of course, use it to plot too, and for stuff doable in matplotlib using the seaborn alternative is much easier and looks better with little or no work. And they support pandas dataframes.
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.
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.
\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).[1] http://www.hrzn.ch/publications/tf-icnp15.pdf [2] http://www.hrzn.ch/publications/thesis.pdf
An interesting tip, never thought of that! It changes the way you write a bit, but it does make finding changes easier, finding errors easier, and forces you to think more about each sentence since you have to hit "enter" at the end of each one.
Then you can use savefig when it looks good. Then save the code you used into some file near the Latex sources.
To standardize appearance I put appearance modifiers in `notebook_context/__init__.py`, and then in my second jupyter cell
from notebook_context import *
configure_plotting_for_publication()
Example notebook_context: https://github.com/maksimt/empirical_privacy/blob/master/src...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.
Not a native speaker, though.
I personally find matplotlib a bit unintuitive to use, so I made a 100-line script for generating SVG. It's great.
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.
I wouldn't be surprised if someone wrote a tool that allows you to use a reference to an equation as the function to plot :).
You can write (or derive) the expression using sympy, then have sympy generate a numpy expression that can be evaluated. Sympy can also generate the LaTeX code for any expression. So while that isn't an in-LaTeX solution, it may be close to what you want.
Johansson's "Numerical Python" shows several examples of this. I will scavenge one of his examples below (trusting it falls under "fair use", and hoping I transcribe it correctly -- note I have left out the imports). The example uses sympy to generate and plot Taylor series expansions of sin(x).
The key bit to look for in the example is `sympy.lambdify()`.
sym_x = sympy.Symbol("x")
x = np.linspace(-2 * np.pi, 2 * np.pi, 100)
def sin_expansion(x, n):
return sympy.lambdify(sym_x, sympy.sin(sym_x).series(n=n+1).removeO(), 'numpy')(x)
fig, ax = plt.subplots()
ax.plot(x, np.sin(x), linewidth=4, color="red", label='exact')
colors = ["blue", "black"]
linestyles = [':', '-.', '--']
for idx, n in enumerate(range(1, 12, 2)):
ax.plot(x, sin_expansion(x, n), color=colors[idx // 3],
linestyle=linestyles[idx % 3], linewidth=3,
label="order %d approx." % (n+1))
ax.set_ylim(-1.1, 1.1)
ax.set_xlim(-1.5*np.pi, 1.5*np.pi)
ax.legend(bbox_to_anchor=(1.02, 1), loc=2, borderaxespad=0.0)
fig.subplots_adjust(right=.75)
I highly recommend the book. It's full of nuggets like this.Also, (v)phantom and smash are something I really should have learned before all those fancy packages, nowadays I'm mostly using context anyways.
Maybe I’m doing something wrong. YMMV
It's API is not as sprawling but understanding the data classes takes some effort.
For 2D, matplotlib or ROOT fit my uses. But, if you think matplotlib is sprawling, you'll hate ROOT.
Please stop using the awful Computer Modern typeface.
Apart from personal preference, why avoid Computer Modern?
Just kidding, but I got my degree 25 years ago, and at the time, the students who tried to have a perfectly typeset document spent a lot of time on that pursuit.
My resume is typeset in Linux Libertine [2] which is used in this superlatively beautiful and elegant CV template by Dario Taraborelli [3]. Requires xelatex.
[1] http://www.tug.dk/FontCatalogue/charterbt/
Or
\usepackage[utopia]{mathdesign}
Some people like garamond (also a mathdesign font).