1

我是 LaTeX 的新手,我希望用它来为我的论文绘制图表。在大多数情况下,我发现它易于使用。我绘制函数没有问题,但我无法从外部 csv 文件中绘制它。我看过很多教程和示例,甚至从其中复制和粘贴了代码,但我什么也做不了。我得到的错误是:

包 pgfplots 错误:无法在“搜索路径 =”中读取表文件“HeatSources.csv”

我认为我遇到的部分问题是没有完整的例子。此处发布的教程和示例通常显示在 tex 文件开头定义的小型数据集,没有完整说明如何使用保存在计算机上的文件查找语法。我在下面的一个教程中包含了整个代码。情节永远不会出现,我总是得到我上面提到的错误^^。谁能告诉我读取 csv 文件的确切语法,包括文件路径应该是什么样的?或者有谁知道我是否偏离了基地并且代码还有其他问题?

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\usepackage{csvsimple}


\pgfplotsset{compat=newest} % Allows to place the legend below plot
\usepgfplotslibrary{units} % Allows to enter the units nicely

\sisetup{
  round-mode          = places,
  round-precision     = 2,
}

\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 0, xmax = 30,
ymin = -1.5, ymax = 2.0,
xtick distance = 5,
ytick distance = 1,
grid = both,
minor tick num = 1,
major grid style = {lightgray},
minor grid style = {lightgray!25},
width = \textwidth,
height = 0.5\textwidth,
]


% add a plot using a file where values are separated by spaces
\addplot[
smooth,
thin,
red,
dashed
] table[col sep=comma, x=Time from start of January 1 (h), y=Transformer (W)]
{HeatSources.csv}{/C:/Users/kayla/OneDrive/Documents/Plots and graphics/HeatSources.csv};

\end{axis}
\end{tikzpicture}
\end{document}

哦,csv 文件的前几行如下所示:

Time from start of January 1 (h),Transformer (W),Elec equipment + lighting (W),Water tanks (W)
0.042,5.4,1194.5,43.75690471
0.125,150,1035,44.32023815

谢谢!

4

0 回答 0