# How to keep xtick label in pgfplots for those coordinates wihout y value

I construct plots by coordinates from table. For some coordinates, the y value is not given which causes the related xtick label disappears. But I want these xtick labels for such coordinates being shown on my plots. How to do it? Here is my MWE:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\usepackage{filecontents}

\begin{document}
\begin{filecontents}{test.dat}
time    id  a
59:58   1   1
59:59   2   4
00:00   3   nan
00:01   4   16
00:02   5   25
\end{filecontents}

\begin{tikzpicture}
\begin{axis}[
title={example},
xlabel=time,
ylabel={$data$},
xticklabel style={rotate=90},
xtick=data,
xticklabels from table={test.dat}{time}
]
\end{axis}
\end{tikzpicture}

\end{document}


• Since the x axis is time, you can try using pgfplots library dateplot and then directly plot time vs data. Dec 15, 2018 at 9:08
• Thank you @nidhin. Yet, the x-axis has to be "id" in my case.
– lyl
Dec 15, 2018 at 10:19
• Is it okay if the 00:00 is not marked but other ticks appear at the correct place? Dec 15, 2018 at 11:24
• I'm afraid not. 00:00 is necessary in my plots.
– lyl
Dec 15, 2018 at 12:44

For this case you could use xtick={1,...,5} instead of xtick=data.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.6}
\usepackage{filecontents}

\begin{document}
\begin{filecontents}{test.dat}
time    id  a
59:58   1   1
59:59   2   4
00:00   3   nan
00:01   4   16
00:02   5   25
\end{filecontents}

\begin{tikzpicture}
\begin{axis}[
title={example},
xlabel=time,
ylabel={$data$},
xticklabel style={rotate=90},
xtick={1,...,5},
xticklabels from table={test.dat}{time}
]

• @lyl Well, with 10000 points you definitely don't want xtick=data anyways. Perhapsxtick={1,901,...,10000}. Dec 16, 2018 at 8:21
• @lyl Sorry, I forgot about the xticklabels from table. that makes it a bit more tricky, but I think I have another answer describing a possible method. Give me a couple of minutes, I'll see if I can find it. Dec 16, 2018 at 8:57