# Pgfplot Automation tool

Are there any good graphical software that I can use to draw diagrams/graphs and export them as pgfplot code?

For example, I want to create an histogram so I drag an histogram icon from a menu to the "scene" and tell the program to load the data from what file.. etc.

-
Just to get you right: you want a software that you can use with a mouse to configure your plots and that in the end saves you a piece of pgfplots code with all the parameters used which you can include into your tex file? – Benedikt Bauer Oct 5 '12 at 15:17
matlab2tikz is somewhat useful if you deal with Matlab figures. But other than that I wouldn't know of any "point and click" software able to export to tikz/pgf/pgfplots. – Markus Oct 5 '12 at 17:54
Benedikt you're right. I already use matlab, but the exported graphs are terrible. But I would like an interface like that with the option to export the resulting graph to pgf. – JohnTortugo Oct 5 '12 at 19:12
Markus this is an excelent tool. thanks. – JohnTortugo Oct 5 '12 at 19:57
@Markus Perhaps you could make that an answer. (And mention matplotlib2tikz as well, just for reference.) – Torbjørn T. Oct 7 '12 at 15:30

## Matplotlib

If you use matplotlib there are at least two options for generating code that can be included in LaTeX files:

• The pgf backend: recent versions of matplotlib has a pgf backend, so you can simply do

plt.savefig('filename.pgf')


to generate a file with pgf code.

• matplotlib2tikz: a script written by Nico Schlömer that generates TikZ/pgfplots code which can be \input in your LaTeX file. See also below.

## Matlab export

matlab2tikz (also available on the MathWorks FileExchange), also written by Nico Schlömer, works as matplotlib2tikz.

One can specify the width and height of the pgfplots plot, and the developer of matlab2tikz recommends defining these as macros, so that they can be changed from within the main LaTeX file.

This allows one to quickly create histograms rendered by pgfplots with consistent size.

### Example

x = randn(10000,1);
hist(x)
matlab2tikz('testfig.tex')


This will generate a file testfig.tex in the current folder, that contains a tikzpicture with an axis environment.

To specify width and height, do for example

matlab2tikz('testfig.tex','width','\figw','height','\figh')


and have LaTeX code such as

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.7}
\usepackage{kantlipsum} % for dummy text
\newlength\figw
\newlength\figh
\setlength\figw{7cm}
\setlength\figh{5cm}

\begin{document}
\kant[1]
\begin{figure}[hb]
\centering
\input{testfig}
\caption{Quite normal}
\end{figure}
\end{document}


-
matplotlib has a pgf backend, if you just want pgf and don't require pgfplots. – G. Poore Mar 13 '13 at 0:13
@G.Poore Thanks, I'd forgotten about that. I'll update my answer. – Torbjørn T. Mar 13 '13 at 8:32

I use Octave. It has the print command with the -dtikz option which exports a plot to PGF/TikZ code.

More precisely, because Octave includes two graphics toolkits:

• When the Gnuplot toolkit is active, this saves TikZ code.
• When FLTK is active, this saves lower-level PGF code.

Also it requires some configuration, because the exported code does not work instantly. The pgfpicture environment has to be changed to tikzpicture, and the TikZ code invokes gnuplot which requires including a package from the Octave supplied texmf tree, and passing the --enable-write18 option to (pdf)latex.

-
And when I got everything working, I decided that I'd rather export my matrices to plain text and use PGFPlots' \addplot table because that's more native and looks better when zoomed in on :) – marczellm Mar 12 '13 at 22:08