How to specify the starting point of a horizontal bar in latex ? For example, I want to plot a horizontal bar between (2, 5) and (10, 5), which is a horizontal bar with a length of 8 and starting at 2. I have tried both bchart package and pgfplots package, but I have no means to work it around. Any help will be appreciated.
Asked
Active
Viewed 1,198 times
3
Zongyi Zhao
- 185
-
First of all, I don't understand what your units are. Second: have you tried TikZ? – Nicolás Ozimica Apr 11 '15 at 03:08
-
No, I haven't tried the Tikz. The units could be em, cm, or any other things. Sorry that I doesn't describe it clearly and make you confusing. Do you suggest me to try Tikz? – Zongyi Zhao Apr 11 '15 at 03:27
-
If you have used pgfplots, you have already used tikz. Tikz is the engine which runs pgfplots. – John Kormylo Apr 11 '15 at 03:40
-
As you suggested, I searched "horizontal bar with tikz" in google and find the a similar result in this. I think that will be enough to solve my problem. Thank you. – Zongyi Zhao Apr 11 '15 at 03:53
1 Answers
5
You can simply draw it by yourself. pgfplots is used to draw the axis while it is possible to draw it using tikz too.
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis y line=left,
axis x line=bottom,
xmin=0,xmax=100,
ymin=0,ymax=10,
ytick={1,2,...,10},
yticklabels={A,B,C,D,E,F,G,H,I,J}
]
\filldraw[blue!40,draw=black] ([yshift=-2.5mm]10,1) rectangle
([yshift=2.5mm]50,1)node[right,yshift=-2.5mm,text=black]{40};
\filldraw[blue!40,draw=black] ([yshift=-2.5mm]2,2) rectangle
([yshift=2.5mm]10,2)node[right,yshift=-2.5mm,text=black]{8};
\filldraw[blue!40,draw=black] ([yshift=-2.5mm]50,3) rectangle
([yshift=2.5mm]75,3)node[right,yshift=-2.5mm,text=black]{25};
\filldraw[blue!40,draw=black] ([yshift=-2.5mm]10,4) rectangle
([yshift=2.5mm]80,4)node[right,yshift=-2.5mm,text=black]{70};
\filldraw[blue!40,draw=black] ([yshift=-2.5mm]50,5) rectangle
([yshift=2.5mm]90,5)node[right,yshift=-2.5mm,text=black]{40};
\end{axis}
\end{tikzpicture}
\end{document}
