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.

Im using the following code from pgfplots to create box plots:

 \begin{tikzpicture}
  \begin{axis}
  [
    ytick={1},
    yticklabels={},
    y=0.7cm
  ]  
  \addplot+[boxplot]
    table[row sep=\\, y index = 0] {
    data\\
      2\\ 2\\ 3\\ 3\\ 4\\ 4\\ 4\\ 4 \\
    };
  \end{axis}
\end{tikzpicture}

This produced a box plot like first one in the following picture:

box plots, first on is the actual one, second is how i would like it to look

In the first box plot it appears as if my data was on a scale from 2 to 4, since all of my results are in that range. The actual range for the data was from 0 to 6. Therefore i would like to show that in the box plot. This is shown in the second box plot in the picture.

How can i do this?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Add the xmin and xmax values:

\documentclass[png,tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}% version
\usetikzlibrary{pgfplots.statistics}

\begin{document}
 \begin{tikzpicture}
  \begin{axis}
  [
    ytick={1},
    yticklabels={},
    y=0.7cm,
    xmin=0,
    xmax=6,
  ]  
  \addplot+[boxplot]
    table[row sep=\\, y index = 0] {
    data\\
      2\\ 2\\ 3\\ 3\\ 4\\ 4\\ 4\\ 4 \\
    };
  \end{axis}
\end{tikzpicture}
\end{document}

The result:

enter image description here

In order to still display the x ticks 2.5 and 3.5, one might exploit the extra x ticks key:

\documentclass[png,tikz,border=10pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}% version
\usetikzlibrary{pgfplots.statistics}

\begin{document}
 \begin{tikzpicture}
  \begin{axis}
  [
    ytick={1},
    yticklabels={},
    extra x ticks={2.5,3.5},
    y=0.7cm,
    xmin=0,
    xmax=6,
  ]  
  \addplot+[boxplot]
    table[row sep=\\, y index = 0] {
    data\\
      2\\ 2\\ 3\\ 3\\ 4\\ 4\\ 4\\ 4 \\
    };
  \end{axis}
\end{tikzpicture}
\end{document}

The result:

enter image description here

but IMHO it is better to keep the previous version or to switch completely to a finer scale, i.e 0.5.

share|improve this answer

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.