5

I am trying to plot a box plot in latex. Below is what I want (only horizontal axis; ticks or axis arrows are options but I do not want axes borders or any vertical axis element).

desired output

The code below is what I have so far with the statistics package:

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepackage{caption}
\usepackage{lscape}
\usetikzlibrary{arrows}
\usepackage{flexisym}
\usepgfplotslibrary{statistics}
\usetikzlibrary{shapes.multipart,shapes.geometric,calc,angles,positioning,intersections,quotes,decorations,babel,patterns,fit}
\usetikzlibrary{decorations.markings}
\newenvironment{tightcenter}{
\setlength\topsep{0pt}
\setlength\parskip{0pt}
\begin{center}}{\end{center}}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}
[
ytick=\empty,
xtick={0,10,15,20,25,30,35,40},
%yticklabels={Index 0, Index 1, Index 2},
axis line style={draw=}
]
\addplot[
boxplot prepared={
median=23,
upper quartile=32,
lower whisker=8,
lower quartile=11,
upper whisker=35
},black
] coordinates {};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

and it generates the box plot below, which is not what I want.

current output

Can you please suggest how to modify the current code to achieve what I want?

Thank you so much.

4

You are loading a lot of things that are not directly related to your problem. Following the example on p. 498 of the pgfplots manual, I suggest to try

\documentclass[]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{pgfplots}
\usepgfplotslibrary{statistics}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{center}
\begin{tikzpicture}
\begin{axis}
[
ytick=\empty,
xtick={0,10,15,20,25,30,35,40},
axis x line=bottom,
axis line style={latex-latex},
axis y line=none,
enlargelimits=0.05,
]
\addplot[
boxplot prepared={
median=23,
upper quartile=32,
lower whisker=8,
lower quartile=11,
upper whisker=35
},black
] coordinates {};
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}

enter image description here

Let me also mention that I like the whiskers from the tikzmarmots package better. ;-)

  • You own package? – Will Kim Aug 13 '18 at 19:28
  • @WillKim No. it is all samcarter's magical work. – user121799 Aug 13 '18 at 19:29
3

You could modify the code like so:

\begin{axis}
[
ytick=\empty,
hide y axis,        % hide the y axis
axis x line*=bottom,% only show the bottom x axis line, without an arrow tip
xtick={0,10,15,20,25,30,35,40},
%yticklabels={Index 0, Index 1, Index 2},
axis line style={draw=}
]

which looks like Updated BoxPlot

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.