Underleaf Logo
Underleaf
PricingAboutBlog
Log InGet started

Learn PGFPlots

Getting Started

  • What is PGFPlots?
  • PGFPlots for Beginners
  • Basic Setup

Box Plots in PGFPlots

Create box and whisker plots for statistical data summaries.

Setup for Box Plots

\usepackage{pgfplots} \usepgfplotslibrary{statistics} \pgfplotsset{compat=1.18}

Basic Box Plot from Data

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=5, upper quartile=7, lower quartile=3, upper whisker=9, lower whisker=1 } ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot from Raw Data

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, ylabel={Value} ] \addplot[ boxplot ] table[y index=0] { data 23 45 32 56 28 67 43 51 38 49 34 62 41 55 29 }; \end{axis} \end{tikzpicture}

Multiple Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, xtick={1, 2, 3}, xticklabels={Group A, Group B, Group C}, ylabel={Score} ] % Group A \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!30 ] coordinates {}; % Group B \addplot[ boxplot prepared={ median=60, upper quartile=75, lower quartile=45, upper whisker=90, lower whisker=25 }, fill=red!30 ] coordinates {}; % Group C \addplot[ boxplot prepared={ median=55, upper quartile=70, lower quartile=40, upper whisker=88, lower whisker=20 }, fill=green!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Horizontal Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=x, ytick={1, 2, 3}, yticklabels={Dataset 1, Dataset 2, Dataset 3}, xlabel={Value} ] \addplot[ boxplot prepared={ draw position=1, median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!30 ] coordinates {}; \addplot[ boxplot prepared={ draw position=2, median=60, upper quartile=75, lower quartile=45, upper whisker=90, lower whisker=25 }, fill=red!30 ] coordinates {}; \addplot[ boxplot prepared={ draw position=3, median=45, upper quartile=60, lower quartile=30, upper whisker=80, lower whisker=10 }, fill=green!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot with Outliers

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=80, lower whisker=20 }, fill=blue!30 ] coordinates { % Outliers (1, 5) (1, 95) (1, 98) }; \end{axis} \end{tikzpicture}

Styled Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, boxplot={ draw/box/.style={thick, blue}, draw/whisker/.style={thick, blue}, draw/median/.style={thick, red} } ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!20 ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot Width

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, boxplot/box extend=0.5 % Box width ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=orange!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Notched Box Plot

Notched box plots show confidence intervals around the median:

% Note: Notches require manual calculation % This shows the concept using draw commands \begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15, % Notch values upper notch=55, lower notch=45 }, fill=purple!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Next Steps

Continue learning PGFPlots:

  • Histograms - Frequency distributions
  • Error Bars - Uncertainty visualization
  • Axis Customization - Advanced axis options

Box Plots in PGFPlots

Create box and whisker plots for statistical data summaries.

Setup for Box Plots

\usepackage{pgfplots} \usepgfplotslibrary{statistics} \pgfplotsset{compat=1.18}

Basic Box Plot from Data

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=5, upper quartile=7, lower quartile=3, upper whisker=9, lower whisker=1 } ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot from Raw Data

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, ylabel={Value} ] \addplot[ boxplot ] table[y index=0] { data 23 45 32 56 28 67 43 51 38 49 34 62 41 55 29 }; \end{axis} \end{tikzpicture}

Multiple Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, xtick={1, 2, 3}, xticklabels={Group A, Group B, Group C}, ylabel={Score} ] % Group A \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!30 ] coordinates {}; % Group B \addplot[ boxplot prepared={ median=60, upper quartile=75, lower quartile=45, upper whisker=90, lower whisker=25 }, fill=red!30 ] coordinates {}; % Group C \addplot[ boxplot prepared={ median=55, upper quartile=70, lower quartile=40, upper whisker=88, lower whisker=20 }, fill=green!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Horizontal Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=x, ytick={1, 2, 3}, yticklabels={Dataset 1, Dataset 2, Dataset 3}, xlabel={Value} ] \addplot[ boxplot prepared={ draw position=1, median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!30 ] coordinates {}; \addplot[ boxplot prepared={ draw position=2, median=60, upper quartile=75, lower quartile=45, upper whisker=90, lower whisker=25 }, fill=red!30 ] coordinates {}; \addplot[ boxplot prepared={ draw position=3, median=45, upper quartile=60, lower quartile=30, upper whisker=80, lower whisker=10 }, fill=green!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot with Outliers

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=80, lower whisker=20 }, fill=blue!30 ] coordinates { % Outliers (1, 5) (1, 95) (1, 98) }; \end{axis} \end{tikzpicture}

Styled Box Plots

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, boxplot={ draw/box/.style={thick, blue}, draw/whisker/.style={thick, blue}, draw/median/.style={thick, red} } ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=blue!20 ] coordinates {}; \end{axis} \end{tikzpicture}

Box Plot Width

\begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y, boxplot/box extend=0.5 % Box width ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15 }, fill=orange!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Notched Box Plot

Notched box plots show confidence intervals around the median:

% Note: Notches require manual calculation % This shows the concept using draw commands \begin{tikzpicture} \begin{axis}[ boxplot/draw direction=y ] \addplot[ boxplot prepared={ median=50, upper quartile=65, lower quartile=35, upper whisker=85, lower whisker=15, % Notch values upper notch=55, lower notch=45 }, fill=purple!30 ] coordinates {}; \end{axis} \end{tikzpicture}

Next Steps

Continue learning PGFPlots:

Underleaf Logo
Underleaf

Empowering students and researchers with AI-powered tools for academic writing.

Go to appContact us

Company

PricingBlogTutorialsAffiliate Program

Free Tools

Image to LaTeXExcel to LaTeXArXiv to LaTeXTikZ GeneratorThesis GeneratorChrome ExtensionAll Tools

© 2026 Underleaf. All rights reserved.