1

I saw a nice way to make a box plot here. But I would like to mark where a specific student is. So can I draw a small ellipse on the box plot. E.g. at 82%?

I am thinking an ellipse is better, because it doesn't block the view of the box plot. But a broader line underneath the box plot would be perfect as well.

    \begin{tikzpicture}
  \begin{axis}
    [cycle list name=mark list,
    width=12cm, height=3.5cm, 
    ytick={1,2,3,4,5,6,7,8},
    yticklabels={Samlet set},
    ]
% Alles data
    \addplot+[black,
    boxplot prepared={
      median=65,
      upper quartile=75.5,
      lower quartile=41,
      upper whisker=97.5,
      lower whisker=12
    },
    ] coordinates {};
  \end{axis}
\end{tikzpicture}
1
  • 1
    Hi and welcome to TeX.se. You can format code by selecting it and clicking on the {} icon. Also it's better to post complete minimal documents rather than code fragments. This makes it easier to see what you are doing exactly, and makes it easier for people to help you.
    – Alan Munn
    Jun 18, 2016 at 16:58

1 Answer 1

1

This creates a filled ellipse 2 percentiles wide and about as as tall as the boxplot. The key is to define coordinates inside the axis environment then do the drawing after.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary[statistics]

\newlength{\xscale}
\newlength{\yscale}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    [cycle list name=mark list,
    width=12cm, height=3.5cm, 
    ytick={1},
    yticklabels={Samlet set},
    ]
    \coordinate (start) at (axis cs: 0,0);% to compute x and y scales
    \coordinate (end) at (axis cs: 1,1);
% Alles data
    \addplot+[boxplot prepared={
      median=65,
      upper quartile=75.5,
      lower quartile=41,
      upper whisker=97.5,
      lower whisker=12
    },
    ] coordinates{};
    \coordinate (A) at (axis cs: 82,1);
  \end{axis}
  \pgfextractx{\xscale}{\pgfpointdiff{\pgfpointanchor{start}{center}}{\pgfpointanchor{end}{center}}}%
  \pgfextracty{\yscale}{\pgfpointdiff{\pgfpointanchor{start}{center}}{\pgfpointanchor{end}{center}}}%
  \fill (A) ellipse[x radius=\xscale,y radius=0.4\yscale];
\end{tikzpicture}

\end{document} 

demo


Here is the same thing using \pgfplotsextra.

\documentclass{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary[statistics]

\newlength{\xscale}
\newlength{\yscale}

\begin{document}

\begin{tikzpicture}
  \begin{axis}
    [cycle list name=mark list,
    width=12cm, height=3.5cm, 
    ytick={1},
    yticklabels={Samlet set},
    ]
  \pgfplotsextra{% compute x and y scales
      \coordinate (start) at (axis cs: 0,0);
      \coordinate (end) at (axis cs: 1,1);
      \pgfextractx{\xscale}{\pgfpointdiff{\pgfpointanchor{start}{center}}{\pgfpointanchor{end}{center}}}%
      \pgfextracty{\yscale}{\pgfpointdiff{\pgfpointanchor{start}{center}}{\pgfpointanchor{end}{center}}}%
    }%
% Alles data
    \addplot+[boxplot prepared={
      median=65,
      upper quartile=75.5,
      lower quartile=41,
      upper whisker=97.5,
      lower whisker=12
    },
    ] coordinates{};
    \pgfplotsextra{\fill (axis cs: 82,1) ellipse[x radius=\xscale,y radius=0.4\yscale];}%
  \end{axis}

\end{tikzpicture}

\end{document} 

You must log in to answer this question.

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