I produce the following chart:
If you look in the table \hchartone, you'll see that I created two separate series (yoy and yoy2) in order to be able to plot the last bar in a different colour.
However, this causes the x-tick label for 1Q20 to be absent.
How do I fix this?
Code to produce the above:
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
\pgfplotsset{compat=1.17}
%colors
\usepackage{color} % colors
\usepackage{xcolor}
\definecolor{c1}{HTML}{122084}
\definecolor{c6}{HTML}{ff8091}
\definecolor{c6d}{HTML}{db4d60}
\begin{document}
%\pagecolor{gray!20!white}
\pgfplotstableread[col sep=comma]{
date, yoy, yoy2
1Q19, 4.5,
2Q19, 4.9,
3Q19, 4.4,
4Q19, 3.6,
1Q20, , -0.3
}\hchartone
\begin{tikzpicture}
\small
\begin{axis}[
width = 6.5cm,
height = 6cm,
axis lines=left,
enlarge x limits={0.1},
enlarge y limits={0.1, upper},
%
% y ticks style and label
ymin = -1.1,
ylabel={Annual change (\%)},
ylabel shift = 0pt,
ytick distance = 1,
y tick label style={/pgf/number format/.cd, fixed, fixed zerofill, precision=1, /tikz/.cd, font=\scriptsize},
%
% x axis ticks and style
xtick=data,
xticklabels from table={\hchartone}{date},
axis x line shift={\pgfkeysvalueof{/pgfplots/ymin}},
xticklabel shift={-\pgfkeysvalueof{/pgfplots/axis x line shift}},
table/x expr = \coordindex,
%
% nodes near coords
nodes near coords,
nodes near coords style = { /pgf/number format/.cd,
fixed, fixed zerofill, precision=1, /tikz/.cd, font=\scriptsize,
},
]
%
% done with the axis, now the plots
\addplot [c1, fill, ybar, nodes near coords, draw opacity = 0]
table [y=yoy] {\hchartone};
\addplot [c6, fill, ybar, nodes near coords style = {color = c6d}, draw opacity = 0]
table [y=yoy2] {\hchartone};
\end{axis}
\end{tikzpicture}
\end{document}




xtick=data,then you get the last tick in, however, every other tick is missing. If you then addxtick distance=1, the last one goes missing again. – May 09 '20 at 23:31xtick=data,the last tick appears but this solution seems to be useless since it has a bad side effect. – May 09 '20 at 23:44xtick=datawithxtick={0,...,4}. – Torbjørn T. May 10 '20 at 07:26