Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Latex 1.95 KB | None | 0 0
  1. % How to draw boxplots with TikZ. Adapted from
  2. % “fluffyk”s example in the LaTeX community forum: http://is.gd/cfSJai
  3.  
  4. \documentclass{article}
  5.  
  6. \usepackage{pgf}
  7. \usepackage{pgfplots}
  8. \usepackage[active,tightpage]{preview}
  9. \usetikzlibrary{fit,calc}
  10. \usepgfplotslibrary{external}
  11. \newcommand{\boxplot}[6]{%
  12.     %#1: center, #2: median, #3: 1/4 quartile, #4: 3/4 quartile, #5: min, #6: max
  13.     \filldraw[fill=white,line width=0.2mm] let \n{boxxl}={#1-0.1}, \n{boxxr}={#1+0.1} in (axis cs:\n{boxxl},#3) rectangle (axis cs:\n{boxxr},#4);   % draw the box
  14.     \draw[line width=0.2mm, color=red] let \n{boxxl}={#1-0.1}, \n{boxxr}={#1+0.1} in (axis cs:\n{boxxl},#2) -- (axis cs:\n{boxxr},#2);             % median
  15.     \draw[line width=0.2mm] (axis cs:#1,#4) -- (axis cs:#1,#6);                                                                           % bar up
  16.     \draw[line width=0.2mm] let \n{whiskerl}={#1-0.025}, \n{whiskerr}={#1+0.025} in (axis cs:\n{whiskerl},#6) -- (axis cs:\n{whiskerr},#6);        % upper quartile
  17.     \draw[line width=0.2mm] (axis cs:#1,#3) -- (axis cs:#1,#5);                                                                           % bar down
  18.     \draw[line width=0.2mm] let \n{whiskerl}={#1-0.025}, \n{whiskerr}={#1+0.025} in (axis cs:\n{whiskerl},#5) -- (axis cs:\n{whiskerr},#5);        % lower quartile
  19.     }
  20.  
  21. \PreviewEnvironment{tikzpicture}
  22.  
  23. \begin{document}
  24. \tikzset{external/remake next}
  25. \begin{tikzpicture}
  26.     \begin{axis}[%
  27.         xmin=0, xmax=6,%
  28.         ymin=-.01, ymax=.4,%
  29.         xtick={1,2,3,4,5},xticklabels={D04,D10,D21,D36,D60}%
  30.         ]
  31.         %#1: center, #2: median, #3: 1/4 quartile, #4: 3/4 quartile, #5: min, #6: max
  32.         \boxplot{1}{.00479}{.001777}{.011400}{0.0000232}{.0209}
  33.         \boxplot{2}{.00828}{.004987}{.018975}{0.0005100}{.1}
  34.         \boxplot{3}{.03300}{.013950}{.088550}{0.0008580}{1.06}
  35.         \boxplot{4}{.06708}{.034778}{.135850}{0.0060770}{5.08}
  36.         \boxplot{5}{.06800}{.033600}{.152500}{0.0000030}{1.51}                     
  37.     \end{axis}
  38. \end{tikzpicture}
  39.  
  40. \end{document}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement