1

I want to construct a plot with package pgfplots using data from a table named "00-data.txt". Following is a part of this table.

id a b  time
1  1 1  23:59:58
2  2 4  23:59:59
3  3 9  00:00:00
4  4 16 00:00:01
5  5 25 00:00:02

The pgfplots option xticklabels from table={00-data.txt}{time} is used to get xticklabel with the data from the column "time".

Yet the xticklabel does not begin with 23:59:58, but 00:00:00(please see the attached figure).

I know the option xtick=data would solve this problem, but there are nearly 10 thousands rows of data in the table, xtick=data would cause too many xticklabels shown on the plot which overlap side by side.

Is there a better way to deal with this problem?

And how to get a dual-xticklabel in a plot, for example, both "id" and "time" are shown in the plot as xticklabel?

Here is my MWE:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}

\begin{tikzpicture}
\begin{axis}[
title={xtick=data not used},
xlabel={$time$},
ylabel={$data$},
xticklabel style={rotate=90},
%xtick=data,
xticklabels from table={00-data.txt}{time} 
]
\addplot [blue] table {00-data.txt};
\addplot table[x=id,y=b] {00-data.txt};
\end{axis}
\end{tikzpicture}

\end{document}    

enter image description here

  • @marmot I tyied your proposal, but get error message "ERROR: Package pgfplots Error: Sorry, could not retrieve column '' from table '00-data.txt'. Please check spelling (or introduce name aliases).." – lyl Dec 3 '18 at 13:00
  • As I don't know how to upload a data file, I provide with the truncated data in my description before my MWE. Copy them directly into a text file(named "00-data.txt" will make a data file. – lyl Dec 3 '18 at 13:47
  • I have no clue what's going on here. And unfortunately I am blocked right now. – marmot Dec 3 '18 at 15:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.