I would like to create a plot like this (maybe a bit better looking - this is my attempt):
Here is how the data for the plot looks:
x,min,max,avg
0,800,3600,2628.571429
1.5,2000,3600,2942.857143
2.0,3000,3600,3300
3.0,3200,4000,3885.714286
4.5,3200,5000,4414.285714
- Can I create a plot like this with pgfplots (i've looked for a plot type like this but could not find it anywhere)?
- Is there any way to get rid of the ugly "scaling" that I do (i.e. divide by 1000)?
- Is there a better way refer to
DTLcurrentindex
without writing it out in full every time? - Is there a better way to read the data from the file?
- Any other glaring mistakes?
My code follows:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usepackage{datatool}
\usetikzlibrary{arrows,backgrounds,snakes}
\begin{document}
\begin{tikzpicture}[>=Stealth]
\DTLloaddb{data}{moose.csv}
\DTLforeach*{data}{\x=x,\min=min, \m=max, \avg=avg}{
% Draw the top whisker
\draw (\DTLcurrentindex - 0.2, \m/1000) -- (\DTLcurrentindex + 0.2, \m/1000);
% Draw the bottom whisker
\draw (\DTLcurrentindex - 0.2, \min/1000) -- (\DTLcurrentindex + 0.2, \min/1000);
% Draw the vertical line
\draw (\DTLcurrentindex, \min/1000) -- (\DTLcurrentindex, \m/1000);
% Draw the middle line
\draw (\DTLcurrentindex - 0.1, \avg/1000) -- (\DTLcurrentindex + 0.1, \avg/1000);
% Draw the x-axis and y-axis
\draw[->] (0,0) -- (6,0);
\draw[->] (0,0) -- (0,6);
\foreach \tick in {1,2,3,4,5}{
\draw (-0.05, \tick) -- (0.05, \tick);
}
% Draw the x tick and label
\draw (\DTLcurrentindex, 0.05) -- (\DTLcurrentindex, -0.05) node[below]{\x};
}
\end{tikzpicture}
\end{document}
pgfplots
if you do not usepgfplots
? (Honest question...) Does this help: tex.stackexchange.com/q/115210/32374