I have a problem with creating a bar plot of demand during a day. My x-coordinates are in "minutes from midnight", but I want to show the time of day on the x-axis at my specified spots (e.g., 6:30 am instead of 390 minutes). xtick
and xticklabels
should do this for me. And they do, when I do not have ybar interval=1
, but then it is no longer the right type of plot.
My code is the following:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[
xtick={390,540,720,900,1020},
xticklabels={6:30,9:00,12:00,15:00,17:00},
ylabel=Required staff,
xlabel=Time of day,
ybar interval=1,
width=0.8\textwidth,
height=5cm,
axis lines=left,
ymin=0
]
\addplot
coordinates {(390,1) (450,2) (510,3) (570,6) (720,3) (735,2) (780,3) (795,4) (930,2) (960,1) (1020,1)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
and it produces:
Outcommenting ybar interval=1,
results in: