我是 Latex 新手,我正在尝试绘制以下 csv,其中包含 Linux 纪元时间(我想将其用作 x 轴)和 uploadtime/totalDocs(我想将其绘制在 y 轴上)。但是我的 Latex 代码总是将其绘制为一条线,使用 xmin/xmax 并没有改善我的情况,您能否告诉我如何改进比例,也许可以给我提供相关文档的链接
谢谢
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}
答案1
一个简单但功能强大的替代方法是让 R 绘制 tikz 图:
平均能量损失:
注意:(1)filecontents
省略,假设data.csv
已经在磁盘上,一旦测试另一个答案(2)文件名必须具有扩展.Rmd
名使用 knitr 编译在 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}
答案2
我可以想象这pgfplots
会带来问题,因为您的 x 值非常大。使用浮点包xfp
并移动 x 值是一种可能的解决方案:
\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}