0

I'm a latex noob and I'm trying to plot the following csv, which contains linux epoch time, which is what i want to use as x axis, and uploadtime/totalDocs which i would like to plot on the y axis. However my latex code always plots it as a single line and using xmin/xmax did not improve my situation, could you please tell me how to improve the scale and maybe link me to the relevant documentation

Thank you

enter image description here

timestamp,uploadtime,totalDocs
1650200149709,274,10000
1650200150676,618,20000
1650200151824,771,30000
1650200152994,837,40000
1650200154867,1492,50000
1650200155908,683,60000
1650200157670,1411,70000
1650200159183,1035,80000
1650200160461,939,90000
1650200161664,851,100000

\begin{document} \begin{tikzpicture} \begin{axis} \addplot table [x=timestamp, y=uploadtime, col sep=comma] {PICS/1_container_load_logs_edit.csv}; \end{axis} \end{tikzpicture} \end{document}

Torbjørn T.
  • 206,688

2 Answers2

1

An easy but powerful alternative is let to R draw the tikz plot:

mwe

MWE:

Notes: (1) filecontents is omitted assuming that data.csv is already on disc once tested the other answer (2) The file name must have the extension .Rmd to be compiled with knitr in Rstudio.

 \documentclass{article}
\begin{document}
<<theplot, dev='tikz', echo=F, fig.align='center', fig.dim=c(5, 3)>>=
df <- read.csv("data.csv",header=T)
df$timestamp2 <-  df$timestamp  - df$timestamp[1] 
plot(df$timestamp2, df$uploadtime, las=1,  ylim=c(0,1500), bty="n",  
     xlab=paste("Time Stamp (starting at $",    format(df$timestamp[1], scientific=T) , "$ )"), 
     ylab="Upload Time", type = "b", pch=21, bg=rainbow(10,start=.4, end=0), lwd=4, col="blue")
@
\end{document}
Fran
  • 80,769
0

I could imagine that pgfplots has problems because your x values are very large. Using the floating point package xfp and shifting the x values is a possible solution:

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usepackage{xfp}

\begin{filecontents}{data.csv} timestamp,uploadtime,totalDocs 1650200149709,274,10000 1650200150676,618,20000 1650200151824,771,30000 1650200152994,837,40000 1650200154867,1492,50000 1650200155908,683,60000 1650200157670,1411,70000 1650200159183,1035,80000 1650200160461,939,90000 1650200161664,851,100000 \end{filecontents}

\begin{document} \begin{tikzpicture} \begin{axis} \addplot table [ x expr={\fpeval{\thisrow{timestamp} - 1650200149709}}, y=uploadtime, col sep=comma, ] {data.csv}; \end{axis} \end{tikzpicture} \end{document}

enter image description here