2

I have data like this in a file.

1 0.1 0.2 0.3 0.8 ...
5 0.3 0.5 0.6 0.9 ...
10 0.2 0.3 0.7 0.10 ..
...

How do I tell boxplot to use the first column as draw position and compute the box for the rest of the data ?

Following is an example, I want to use 5 and 8 as drawing position.

   \documentclass[crop=false]{standalone}
    \usepackage{pgfplotstable}
    \pgfplotsset{compat=1.8}
    \usepgfplotslibrary{statistics}
    \makeatletter
    \pgfplotsset{
        boxplot prepared from table/.code={
            \def\tikz@plot@handler{\pgfplotsplothandlerboxplotprepared}%
            \pgfplotsset{
                /pgfplots/boxplot prepared from table/.cd,
                #1,
            }
        },
        /pgfplots/boxplot prepared from table/.cd,
            table/.code={\pgfplotstablecopy{#1}\to\boxplot@datatable},
            row/.initial=0,
            make style readable from table/.style={
                #1/.code={
                    \pgfplotstablegetelem{\pgfkeysvalueof{/pgfplots/boxplot prepared from table/row}}{##1}\of\boxplot@datatable
                    \pgfplotsset{boxplot/#1/.expand once={\pgfplotsretval}}
                }
            },
            make style readable from table=lower whisker,
            make style readable from table=upper whisker,
            make style readable from table=lower quartile,
            make style readable from table=upper quartile,
            make style readable from table=median,
            make style readable from table=lower notch,
            make style readable from table=upper notch
    }
    \makeatother


    \pgfplotstableread{
        index lw lq med  uq uw
        5  5  7 8.5 9.5 10
        8  4  5 6.5 8.5 9.5
    }\datatable


    \begin{document}
    \begin{tikzpicture}
    \begin{axis}[boxplot/draw direction=y]
      \addplot+[
      boxplot prepared from table={
        table=\datatable,
        lower whisker=lw,
        upper whisker=uw,
        lower quartile=lq,
        upper quartile=uq,
        median=med
      }, boxplot prepared
      ]
      coordinates {};
      \addplot+[
      boxplot prepared from table={
        table=\datatable,
        row=1,
        lower whisker=lw,
        upper whisker=uw,
        lower quartile=lq,
        upper quartile=uq,
        median=med
      }, boxplot prepared
      ]
      coordinates {};
    \end{axis}
    \end{tikzpicture}
    \end{document}
  • Please help us to help you by posting a minimum working example with fully compilable code, illustrating your problem. – JMP Apr 13 '16 at 21:35
  • added an example i'm working on – iKid Apr 13 '16 at 21:50
  • 1
    Related (the basis of the code sample): tex.stackexchange.com/q/117435/2552 – Jake Apr 14 '16 at 6:51
0

You just can use the option draw position, see the manual in section 5.12, pp. 470.

Edited Code:

\documentclass[crop=false]{standalone}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{statistics}
\makeatletter
\pgfplotsset{
    boxplot prepared from table/.code={
        \def\tikz@plot@handler{\pgfplotsplothandlerboxplotprepared}%
        \pgfplotsset{
            /pgfplots/boxplot prepared from table/.cd,
            #1,
        }
    },
    /pgfplots/boxplot prepared from table/.cd,
        table/.code={\pgfplotstablecopy{#1}\to\boxplot@datatable},
        row/.initial=0,
        make style readable from table/.style={
            #1/.code={
                \pgfplotstablegetelem{\pgfkeysvalueof{/pgfplots/boxplot prepared from table/row}}{##1}\of\boxplot@datatable
                \pgfplotsset{boxplot/#1/.expand once={\pgfplotsretval}}
            }
        },
        make style readable from table=lower whisker,
        make style readable from table=upper whisker,
        make style readable from table=lower quartile,
        make style readable from table=upper quartile,
        make style readable from table=median,
        make style readable from table=lower notch,
        make style readable from table=draw position,
        make style readable from table=upper notch
}
\makeatother


\pgfplotstableread{
    index lw lq med  uq uw
    5  5  7 8.5 9.5 10
    8  4  5 6.5 8.5 9.5
}\datatable


\begin{document}
\begin{tikzpicture}
\begin{axis}[boxplot/draw direction=y]
  \addplot+[
  boxplot prepared from table={
    table=\datatable,
    lower whisker=lw,
    upper whisker=uw,
    lower quartile=lq,
    upper quartile=uq,
    median=med
  }, boxplot prepared={,},
  ]
  coordinates {};

  \addplot+[
  boxplot prepared from table={
    table=\datatable,
    row=1,
    lower whisker=lw,
    upper whisker=uw,
    lower quartile=lq,
    upper quartile=uq,
    draw position = index,
    median=med,
  }, boxplot prepared={},
  ]
  coordinates {};
\end{axis}
\end{tikzpicture}
\end{document}

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.