Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Hi I want to change the distance between 2 adjacent boxes in boxplot. I am using following code. What should I change in code to get it similar to as desirable diagram

\begin{filecontents}{lmpqd.dat}
%index median box_top box_bottom whisker_top whisker_bottom
  0.35 56 393.5 14 1374 2
  0.36 35.5 158 6 2693 2
  0.37 10 60.5 3 2014 2
  0.38 10 36 3 2187 2
  0.39 8.5 43.75 3 2131 2
  0.40 6 19 2 2295 2
  0.41 6 26 3 2322 2
  0.42 6 26 2 2621 1
  0.43 3 10 2 1669 2
  0.44 4 14 2 1817 2
  0.45 3 5 2 52 2

\end{filecontents}


\pgfplotsset{
box plot width/.initial=5em,
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} [enlargelimits=false,xmin=0.33,xmax=0.47,xtick=data, box plot width=0.5em]
  \addplot [box plot median] table {lmpqd.dat};
  \addplot [box plot box] table {lmpqd.dat};
  \addplot [box plot top whisker] table {lmpqd.dat};
  \addplot [box plot bottom whisker] table {lmpqd.dat};
\end{axis}
\end{tikzpicture}
%     \captionof{figure}{Boxplot for total number of keys examined by MSB+LSB reconstruction algorithm for $2048-bit$ N, varying $\delta$.}
\label{lmpqd}
\end{document}

But I am getting following box plot Result of above code

While I need it to be as below Desired

share|improve this question

1 Answer 1

up vote 5 down vote accepted

You can either adjust the width and height settings to change the aspect ratio of the plot, for example by setting it to width=12cm, height=6cm, or you can set the x unit vector length, for example to x=80cm. That way, the plot will automatically grow if you add more values:

\documentclass{article}
\usepackage{pgfplots}
\usepackage{filecontents}

\begin{filecontents}{lmpqd.dat}
%index median box_top box_bottom whisker_top whisker_bottom
  0.35 56 393.5 14 1374 2
  0.36 35.5 158 6 2693 2
  0.37 10 60.5 3 2014 2
  0.38 10 36 3 2187 2
  0.39 8.5 43.75 3 2131 2
  0.40 6 19 2 2295 2
  0.41 6 26 3 2322 2
  0.42 6 26 2 2621 1
  0.43 3 10 2 1669 2
  0.44 4 14 2 1817 2
  0.45 3 5 2 52 2

\end{filecontents}

\pgfplotsset{
box plot width/.initial=5em,
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} [ymode=log, enlargelimits=false,xmin=0.34,xmax=0.46,xtick=data, box plot width=0.5em, log ticks with fixed point, ymin=0.9, x=80cm]
  \addplot [very thick, box plot median] table {lmpqd.dat};
  \addplot [box plot box] table {lmpqd.dat};
  \addplot [box plot top whisker] table {lmpqd.dat};
  \addplot [box plot bottom whisker] table {lmpqd.dat};
\end{axis}
\end{tikzpicture}
%     \captionof{figure}{Boxplot for total number of keys examined by MSB+LSB reconstruction algorithm for $2048-bit$ N, varying $\delta$.}
\label{lmpqd}
\end{document}
share|improve this answer
    
Thank you very much, it worked :) –  pratibha Jul 19 '13 at 10:13
    
How can I change the thickness of median –  pratibha Jul 21 '13 at 7:45
1  
@pratibha: You just add the desired style (very thick, for example) to the options of \addplot [box plot median] –  Jake Jul 22 '13 at 11:30
    
Thank you Jake. Is there a way to change the ticks on y axis same as ticks in the example? –  pratibha Jul 23 '13 at 7:24
    
@pratibha: You can remove the ymode=log option to get a linear y axis. –  Jake Jul 24 '13 at 12:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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