0

Yesterday I learnt how to make simpe plots using tikzpicture and I'm very satisfied of the result:

    \begin{tikzpicture}[thick,scale=0.6]
    \begin{axis}[
        xlabel=$\delta$,
        ylabel=$U_2$]
    \addplot[smooth,mark=*,blue] plot coordinates {
        (1,4)
        (4,2)
    };
    \addlegendentry{$\beta_2$}
    \addplot[smooth,color=red,mark=x]
        plot coordinates {
            (1,0)
            (4,9)
        };
    \addlegendentry{$\beta_1$}
    \end{axis}
    \end{tikzpicture}

However now I have to make more complex plots (e.g. boxplot) and I cannot think of doing it manually. Up to now I have a Matlab script which reads a certain amount data and generates a figure. I exclude to save it as .png anymore because I want a vectorial image inside my document.
The better way I found is to use matlab2tikz. I tried it but it gives me errors. Because I cannot access newer versions of Matlab (which wouldn't resolve anything, I think, as the figure is generated without errors. The errors are when I compile LaTeX code.) and because I don't like to deal eternally with parser errors (I have few time so I cannot risk to loose too much time on this) I was looking for another way of doing it.

What do other people do when they want to add a vectorial plot from matlab/octave/gnuplot? Is matlab2tiks the gold standard or is there some other way?

(I know that I could compute my personal tikz boxplot from raw data with a not-too-complex script, and I like the idea, but I'm guessing if there is already something that does it)

  • What errors do you get when you compile the code from matlab2tikz? – Torbjørn T. Feb 19 '14 at 9:58
  • @TorbjørnT. They are 98. I'm trying to find a way of copying and pasting them from Kyle. I cite you a couple: "Missing \endcsname inserted };" here's another: "There is not line to end };" and so on. – HAL9000 Feb 19 '14 at 10:05
  • The first one(s) could be the most important. Open the .log file and you'll find them. – Torbjørn T. Feb 19 '14 at 10:07
  • @TorbjørnT. The first two errors are those I wrote. I put the log here: pastebin.com/wi4dkzYu and the .tex here: pastebin.com/Y1Kzq8Up and the tikz here: pastebin.com/Npig30W6 if you want take a look. Thank you! – HAL9000 Feb 19 '14 at 10:15
  • 1
    You have an outdated TeX-distribution, with old versions of TikZ and pgfplots. On my system (a recently updated TeX Live 2013) your plot works fine. Install TeX Live 2013 from TUG.org (see e.g. tex.stackexchange.com/questions/1092/…) if you can. – Torbjørn T. Feb 19 '14 at 10:33
2

Boxplots are described in chapter 5.9.1 of the PGFPLOTS manual.

Like so:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\begin{document}

\begin{tikzpicture}
  \begin{axis}
    [
    ytick={1,2,3},
    yticklabels={Index 0, Index 1, Index 2},
    ]
    \addplot+[
    boxplot prepared={
      median=1,
      upper quartile=1.2,
      lower quartile=0.4,
      upper whisker=1.5,
      lower whisker=0.2
    },
    ] coordinates {};
    \addplot+[
    boxplot prepared={
      median=2,
      upper quartile=2.3,
      lower quartile=1.5,
      upper whisker=2.7,
      lower whisker=1
    },
    ] coordinates {};
    \addplot+[
    boxplot prepared={
      median=0.7,
      upper quartile=1.4,
      lower quartile=0.5,
      upper whisker=1.9,
      lower whisker=0.1
    },
    ] coordinates {};
  \end{axis}
\end{tikzpicture}

\end{document}

boxplot

If you do want to use matlab. Try to save your image as a pdf or eps, since it is vector based, you won't loose quality.

  • I tried to "print file.pdf" from matlab and it actually looses quality. Moreover I'd prefer to have a tikz figure in order to customize it from tex editor. I didn't try .eps, maybe I'll try it later, thank you for the answer! – HAL9000 Feb 19 '14 at 10:47
  • I would prefer the tikz option as well. But do note that the matlab print command has an option -r to set the resolution of the graphic - try setting it to something like -r300 (it will be the dpi quality) – dorien Feb 19 '14 at 11:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.