Hi,

Were you aware that matplotlib itself has a PGF/TikZ backend 
http://matplotlib.org/users/pgf.html ?

With it one does not need to use matplotlib2tikz, and one can save plots 
either as PFG files, prepared to
be included in some LaTeX document, or directly as PDF.

It took me long time to figure out how to properly tell matplotlib (from 
within Julia) to use that backend to
save PDF (I had to use PyCall in the end), but since then I've been 
successfully using this feature in Julia.

An example of how to save a figure in PGF source:

using PyPlot

##### plot appearance setup
linewidth = 0.4
plt.rc("axes", linewidth=linewidth)
plt.rc("font", family="")
plt.rc("axes", titlesize="small", labelsize="small")
plt.rc("xtick", labelsize="x-small")
plt.rc("xtick.major", width=linewidth/2)
plt.rc("ytick", labelsize="x-small")
plt.rc("ytick.major", width=linewidth/2)
plt.rc("legend", fontsize="small")

#### plot
x = linspace(0,2pi,100);
fig = plt.figure(figsize=(3,2));
plot(x,sin(x),color="red");
title(L"Test plot");
xlabel(L"$x$");
ylabel(L"$\sin(x)$");

#### save plot as PGF source (no setup needed)
plt.savefig("test.pgf")

If one wants to directly generate a PDF, then

### setup matplotlib to save PDF with the PGF backend (tricky in Julia)
using PyCall
backend_pgf = pyimport("matplotlib.backends.backend_pgf")
backend_bases = pyimport("matplotlib.backend_bases")
backend_bases[:register_backend]("pdf", backend_pgf[:FigureCanvasPgf])

### setup PGF-PDF backend output appearance
plt.rc("pgf", texsystem="pdflatex",
              preamble=L"""\usepackage[utf8x]{inputenc}
                           \usepackage[T1]{fontenc}
                           \usepackage{lmodern}""")

#### save directly as PDF (there is NO need to save as PFG first)
plt.savefig("test.pdf", transparent=true)

I think you can make your package to use this features.

Cheers,
Cristóvão

On Monday, May 12, 2014 11:04:13 AM UTC+1, Oliver Lylloff wrote:
>
> Hello all, 
>
> For several years (in the dark Matlab-ages before Julia), I used 
> matlab2tikz <https://github.com/nschloe/matlab2tikz> to generate nice 
> looking pdf figures for academic reports. It's a nice tool and I personally 
> like the idea that my data is exported from matlab to a .tikz or .tex file 
> that I can make changes to without having to open matlab and reexport my 
> figures.
>
> Julia already has some very nice plotting features in Winston, Gadfly and 
> matplotlib (IJulia), am I forgetting someone? The exporting options are 
> good and useful for many different purposes. However, for me, there's 
> something extraordinary about the tikz/pgf plots that I haven't been able 
> to reproduce with these packages. 
>
> Therefore I've made a quick-and-dirty module 
> https://github.com/1oly/PrintFig.jl that uses PyCall to call 
> matplotlib2tikz <https://github.com/nschloe/matplotlib2tikz>, a close 
> relative to matlab2tikz, that exports figure objects to a .tex file using 
> the standalone latex documentclass. I like this approach and it creates the 
> figures that I like for academic work. It's not the intention to add this 
> to METADATA but merely to get a discussion going - if anyone is interested 
> at all...
>
> If anyone has comments, suggestions or want to discuss workflows for 
> generating latex friendly plots, don't be shy :)
>
> Cheers,
> Oliver
>

Reply via email to