I can generate the .pgf without having to setup the backend which I think
is the expected behavior. According to the docs:
"Figures can also be directly compiled and saved to PDF with
plt.savefig('figure.pdf') by either switching to the backend..."
So it seems its only needed to save the PDFs... You may try directly in
Python to see what hapens.

About the settings, I do copy-paste and change them as I need for each
plot.


On Tue, May 13, 2014 at 11:03 AM, Oliver Lylloff <[email protected]>wrote:

> Hi,
>
> Were you aware that matplotlib itself has a PGF/TikZ backend
>> http://matplotlib.org/users/pgf.html ?
>>
>
> No but this is really cool I think!
>
>
>> 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")
>>
>>
> On my setup (both in IJulia and REPL) I still need to do the pyimport of
> the pgf backend to save as a "test.pgf". Is that just me?
>
>
>
>> 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.
>>
>
> This would certainly be easy to implement. One small thing, a matter of
> taste I would say, is that since I like to have figures saved both as
> .pgf/.tikz/.tex and pdf, the pgf files are quite difficult to read (for me
> at least) and therefore also more difficult to make corrections to. In the
> .pgf case I would probably just run my plot script one more time with my
> changes.
>
> Do you have all your settings (the plt.rc parameters) ready each time you
> savefig or do you copy-paste or have a module?
>
> Cheers,
> Oliver
>

Reply via email to