add tag
topnush
What's the simplest way to draw a nice version of:

![IpwAs7L.png](/image?hash=b923e9ef7f681a88bed549b989e9ba95b9d44087d505bb7276ce36c74dd9eb17)

The numbers are meant to be vertically aligned (except for 5 of course), the intervals the same length and the bar heights should be -2, 3, -1. It would be great to have ticks too. The horizontal line should finish at the end of the 8 interval too.
Top Answer
marmot
I'd use `pgfplots`. It may be that the documentation is a bit overwhelming when you look at it for the first time, but this is just because it has many well-documented options that one can play with.
```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,bar width=5mm,
	axis lines=middle,
	xmin=0,xmax=10,
	xtick={1,...,8},ytick=\empty,
	x axis line style={-},
	y axis line style={draw=none}]
 \addplot[fill=none] coordinates {(2,-2) (5,3) (8,1)};
\end{axis}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-10-22 at 8.39.12 AM.png](/image?hash=15560635d4395e68e26f71b753717e5e24be068a72373e881e74689ce352da02)

There are many things you could change. You could fill the bars, plot the data directly from a file and so on and so on.
```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{filecontents}[overwrite]{mybars.dat}
x	y
2	-2
5	3
8	1
\end{filecontents}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,
	width=10cm,height=5cm,bar width=5mm,
	xmin=0,xmax=10,
	xtick={1,...,8}]
 \addplot table {mybars.dat};
\end{axis}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-10-22 at 8.44.08 AM.png](/image?hash=b6ee66eae726017f0eb66a38f3e3bb5ddf668bcd04e7d16fb0e1a6a7405c2f30)

You can change the tick labels at will. Here I show two methods, there are alternatives which play more with `xtricklabel` but may be considered "hacky" and other alternatives.
```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17}
\begin{document}
\begin{tikzpicture}
\begin{axis}[ybar,bar width=5mm,
	width=10cm,height=5cm,
	axis lines=middle,
	xmin=0,xmax=10,
	xtick={1,...,4,6,7},
	xticklabel style={anchor=south,text depth=0.5ex},
	extra x ticks={5,8},
	extra x tick style={xticklabel style={anchor=north}},	
	ytick=\empty,
	x axis line style={-},
	y axis line style={draw=none}]
 \addplot[fill=blue!50!white] coordinates {(2,-2) (5,3) (7,-1)};
\end{axis}
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-10-22 at 9.14.09 AM.png](/image?hash=a91e7fd2a5d6832a0b0479c813a6ed7c344a3b35bf58b8f785eb3fa97d08aed7)

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.