0

Credit where credit is due: I found this wonderful boxplot, im trying to fit my dataset into it and i am failing miserably. My main Problem is, that Miktex is not giving out any error message that i can follow up on my search. Has anyone an Idea? My wild goosechase is not getting me any closer. The original works wonderfully.


    \documentclass{minimal}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.18} % added by me after an errormessage: "Package pgfplots Warning: running in backwards compatibility mode (unsuitable tick labels; missing features). Consider writing \pgfplotsset{compat=1.18}"
    \begin{filecontents}{testdata.dat}
Funny 9 2019 294 615 1818
hilarious 12 1167 301 178 404
hilariouslyfunnylol 11 1954 318 178 389
notsofunny 12 1954 308 183 382
quitefunny 12 1479 303 183 393
bunnyfunny 17 1568 307 187 403
hileriousreligious 14 1178 256 156 339
I 17 1659 285 180 342
ran 14 982 277 185 353
out 9 1032 279 182 351
of 15 1231 276 167 358
ideas 15 1576 260 156 335
damnit 9 2019 314 181 387
    \end{filecontents}

    \pgfplotsset{
     box plot width/.initial=1em,
     box plot/.style={
        /pgfplots/.cd,
        black,
        only marks,
        mark=-,
        mark size=\pgfkeysvalueof{/pgfplots/box plot width},
        /pgfplots/error bars/.cd,
        y dir=plus,
        y explicit,
     },
     box plot box/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \draw  ##1 -- ++(\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##2 -- ++(-\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##1 -- cycle;
        },
        /pgfplots/table/.cd,
        y index=2,
        y error expr={\thisrowno{3}-\thisrowno{2}},
        /pgfplots/box plot
     },
     box plot top whisker/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
            {\pgfplotserrorbarsmark}%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
            {\pgfplotserrorbarsmarkopts}%
            \path ##1 -- ##2;
        },
        /pgfplots/table/.cd,
        y index=4,
        y error expr={\thisrowno{2}-\thisrowno{4}},
        /pgfplots/box plot
     },
     box plot bottom whisker/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
            {\pgfplotserrorbarsmark}%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
            {\pgfplotserrorbarsmarkopts}%
            \path ##1 -- ##2;
        },
        /pgfplots/table/.cd,
        y index=5,
        y error expr={\thisrowno{3}-\thisrowno{5}},
        /pgfplots/box plot
     },
     box plot median/.style={
        /pgfplots/box plot
     }
    }

    \begin{document}
    \begin{tikzpicture}
    \begin{axis} [enlarge x limits=0.5,xtick=data, box plot width=0.5em]
     \addplot [box plot median] table {testdata.dat};
     \addplot [box plot box] table {testdata.dat};
     \addplot [box plot top whisker] table {testdata.dat};
     \addplot [box plot bottom whisker] table {testdata.dat};
    \end{axis}
   \end{tikzpicture}
    \end{document} 
2
  • Hi, welcome. Really, you do not get any error? I have zillions of them, of type Package PGF Math Error: Could not parse input 'notsofunny' . Basically the code you copied expects a number for the first column...
    – Rmano
    Oct 26, 2023 at 10:44
  • 1
    I found the problem, it was still using the "old" .dat file from the sample. I have renamed the file and got one an errormessage to not use letters in my data as you pointed out. Redid them all and changed the filename. realised too late i also need to rename the ones in the bottom too. I have a working one now - Its just damn ugly :D Thank you for pointing that one out!
    – schaewol
    Oct 26, 2023 at 11:58

2 Answers 2

1

The problem is that the x values are symbolic, not numeric. The following code works (although clearly needs a bit of love to adjust things).

Surely there is a way to take automatically the symbolic names from the table, but I have not found it (yet, little time available now).

\documentclass{minimal}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18} % added by me after an errormessage: "Package pgfplots Warning: running in backwards compatibility mode (unsuitable tick labels; missing features). Consider writing \pgfplotsset{compat=1.18}"
\begin{filecontents}{testdata.dat}
    Funny                9   2019  294  615  1818
    hilarious            12  1167  301  178  404
    hilariouslyfunnylol  11  1954  318  178  389
    notsofunny           12  1954  308  183  382
    quitefunny           12  1479  303  183  393
    bunnyfunny           17  1568  307  187  403
    hileriousreligious   14  1178  256  156  339
    I                    17  1659  285  180  342
    ran                  14  982   277  185  353
    out                  9   1032  279  182  351
    of                   15  1231  276  167  358
    ideas                15  1576  260  156  335
    damnit               9   2019  314  181  387
\end{filecontents}

\pgfplotsset{
    box plot width/.initial=1em,
    box plot/.style={
        /pgfplots/.cd,
        black,
        only marks,
        mark=-,
        mark size=\pgfkeysvalueof{/pgfplots/box plot width},
        /pgfplots/error bars/.cd,
        y dir=plus,
        y explicit,
    },
    box plot box/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \draw  ##1 -- ++(\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##2 -- ++(-\pgfkeysvalueof{/pgfplots/box plot width},0pt) |- ##1 -- cycle;
        },
        /pgfplots/table/.cd,
        y index=2,
        y error expr={\thisrowno{3}-\thisrowno{2}},
        /pgfplots/box plot
    },
    box plot top whisker/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
            {\pgfplotserrorbarsmark}%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
            {\pgfplotserrorbarsmarkopts}%
            \path ##1 -- ##2;
        },
        /pgfplots/table/.cd,
        y index=4,
        y error expr={\thisrowno{2}-\thisrowno{4}},
        /pgfplots/box plot
    },
    box plot bottom whisker/.style={
        /pgfplots/error bars/draw error bar/.code 2 args={%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark}%
            {\pgfplotserrorbarsmark}%
            \pgfkeysgetvalue{/pgfplots/error bars/error mark options}%
            {\pgfplotserrorbarsmarkopts}%
            \path ##1 -- ##2;
        },
        /pgfplots/table/.cd,
        y index=5,
        y error expr={\thisrowno{3}-\thisrowno{5}},
        /pgfplots/box plot
    },
    box plot median/.style={
        /pgfplots/box plot
    }
}

\begin{document}
\begin{tikzpicture}
    \begin{axis} [enlarge x limits=0.5,xtick=data, box plot width=0.5em, 
        x tick label style={rotate=90,anchor=east}, symbolic x coords={
            Funny,
            hilarious,
            hilariouslyfunnylol,
            notsofunny,
            quitefunny,
            bunnyfunny,
            hileriousreligious,
            I,
            ran,
            out,
            of,
            ideas,
            damnit,
        }
        ]
        \addplot [box plot median] table {testdata.dat};
        \addplot [box plot box] table {testdata.dat};
        \addplot [box plot top whisker] table {testdata.dat};
        \addplot [box plot bottom whisker] table {testdata.dat};
    \end{axis}
\end{tikzpicture}
\end{document} 

enter image description here

0

I found the problem, it was still using the "old" .dat file from the sample. I have renamed the file and got one errormessages that i should only use numbers. Even tho changing the .dat file in Miktex changed the File contents - as i checked them with an editor - Miktex was still using the one from the previous run through. Which also consequently gave me the errormessage that i should change all to numbers even though i already changed it in the file. The solution is to always change the filenames everywhere in the document. Texmaker 5.0.4 and Miktex 4.9

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Oct 26, 2023 at 12:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .