I am trying to reproduce the following example. The xbar and ybar options are not really what I am looking for since I am only interested in having horizontal lines as markers of points.

Is there any way to do that in pgfplots ?

enter image description here


I assume that the length of the horizontal bars does not carry additional information, but is merely aesthetic. You can use the option mark=- to get horizontal lines, the thickness can be controlled with line width, the "radius" (i.e. half the length) can be set with mark size.

You didn't specifically ask for it, but since you said you're trying to reproduce the example, I also added symbolic x coordinates and and formatted the x tick labels to show the letter in brackets:




\begin{axis}[only marks,
  every axis plot post/.style={mark=-,ultra thick,mark size=4pt},
  symbolic x coords={a,b,c,d},
\addplot +[red] coordinates {
\addplot +[blue] coordinates {


horizontal bars as markers

  • I had tried the mark=- option but didn't thought of combining it with mark size to increase the length ! Anyway, that's exactly waht I was looking for. Many thanks for your prompt answer and the detailed explanation. – FFF Jun 5 '11 at 12:00
  • I actually still have one question: when using the nodes near coords option to get values near markers, if two markers are too close, nodes are overlapping (set (a,-3.8) and (a,-3.75) for instance). Is it possible to specifically shift some of these automatically-generated nodes ? Thanks ! – FFF Jun 5 '11 at 12:38
  • @FFF: There's no easy way to move individual markers. What I would probably do in your case is to use the option nodes near coords align=south option for the upper plot and nodes near coords align=north for the lower plot. However, this really only makes sense if one of the plots is always higher than the other. If you do need a way to move individual markers, you should probably ask a new question. Also, if you consider the current question about the horizontal markers to be answered, you should accept the answer by clicking the green tick mark. – Jake Jun 5 '11 at 14:39
  • many thanks. Using something like nodes near coords align={anchor=south} was enough in my case to solve the overlapping problem. – FFF Jun 5 '11 at 15:48

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.