4

Basically I've been writing my work with XeLaTeX enthusiastically now for about a year and love it, but today for the first time I tried to draw a graph and realised I still have a lot to learn. Unfortunately, I couldn't quite work out how to create a chart looking like the one in my (hastily sketched) image, and I couldn't extract the useful information from PGFPlots manual without getting totally lost.

The chart (graph?) I want to make should be of distinct categories on the x axis, with lines representing ranges of values on the y. I feel certain this is simple but just can't seem to get a handle on it. peculiar graph style

Any guidance would be so greatly appreciated.

1 Answer 1

4

I would use the error bars mechanism for drawing the lines. For getting text labels, I would simply provide the list of labels using xticklabels={A,B,C}.

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    xtick=data, % Only put labels at positions of data points
    xticklabels={A,B,C} % Provide text for labels
]
\addplot [
    only marks, % No lines between the points
    mark=empty, % No marks at the points
    error bars/y dir=plus,  % Error bars in the positive direction
    error bars/y explicit,  % We provide the values for the error bars
    error bars/error mark=empty,    % No markers at the end of the error bars
    error bars/error bar style={thick}  % Use thick lines for the error bars
] table [
    y error expr=\thisrow{Y2} - \thisrow{Y1} % Calculate the length of the error bars
] {
X Y1 Y2
1 100 110
2 110 120
3 100 120
};
\end{axis}
\end{tikzpicture}
\end{document}
1
  • 1
    You sir are a scholar and a gentleman. Thanks for the comments too, really clear.
    – alice19
    Sep 15, 2013 at 18:27

You must log in to answer this question.

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