我正在尝试绘制一个从 .csv 文件导入数据的图表,但每次它崩溃时我都无法得到我想要的结果。我尝试使用类似的 .csv 文件执行相同的代码,并且成功了,所以我被这个问题困住了。这是我尝试绘制的“week1.csv”文件的内容:
time;sensor;simulated
1;19.5;19.49464548
2;19;19.17700791
3;18.8;18.86136048
4;18.6;18.54761463
5;18.4;18.23280342
6;18.3;17.92352567
7;18.1;17.62078638
8;18;17.31792151
9;18.2;17.01524028
10;18.4;16.72588304
11;18.1;17.11651363
12;17.9;17.77873087
13;17.9;18.15327621
14;17.8;17.95555478
15;17.7;17.74795501
16;17.6;17.52594093
17;17.5;17.29089669
18;17.5;17.04891717
19;19;16.81216107
20;18.9;17.27730302
21;19.1;17.94622146
22;19.1;18.59686856
23;19;18.98953883
24;19.1;18.99968524
25;18.6;18.77590152
26;18.1;18.53879784
27;17.9;18.31538976
28;17.7;18.10095345
29;17.6;17.90183671
30;17.4;17.70783841
31;17.3;17.52240945
32;17.2;17.34032281
33;17.9;17.74491767
34;18.2;18.17176908
35;17.7;17.99280995
36;17.5;17.84541031
37;17.7;17.71454988
38;17.5;17.60762704
39;17.5;17.51463032
40;17.3;17.38723956
41;17.1;17.24170862
42;17.2;17.44086405
43;19;18.16053655
44;18.9;18.85514275
45;19;18.99956759
46;19;18.99635606
47;19.1;18.99870573
48;19.1;18.99918397
这是我的代码:
\documentclass[pdftex, a4paper, 11pt]{book}
\input{content/packages&settings}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{figure}[t]
\centering
\pgfplotsset{every axis legend/.append style={font={\scriptsize}}}
\pgfplotsset{every axis legend/.append style={at={(0.5,1.03)},anchor=south}}
\pgfplotsset{every axis legend/.append style={
font={\scriptsize}}}
\begin{tikzpicture}
\begin{axis}[
height=3.5cm,
width=11cm,
axis y line=left,
axis line style=-,
y axis line style=-,
tick label style={font=\scriptsize},
label style={font=\scriptsize},
title style={font=\scriptsize},
xlabel={Time [days]},
ylabel={Power [kW]},
legend columns = 2,
legend style={draw=none, fill=none}
]
\addplot[color=black, mark=] table[col sep=semicolon,trim cells=true,
y=sensor]{data/week1.csv};
\addlegendentry{Measured}
\addplot[color=red, mark=] table[col sep=semicolon,trim cells=true,
y=simulated] {data/week1.csv};
\addlegendentry{Simulated}
\end{axis}
\end{tikzpicture}
\caption{Worse mismatches between the power production as measured and
forecasted during week 22 of 2016. Data taken from , DSO Régie de Wavre.}
\label{fig:ch7-1-pv}
\end{figure}
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
我要导入的 package&settings.tex 文件如下:
\usepackage{notes}
\usepackage[parfill]{parskip}
\usepackage{gensymb}
\usepackage{amsmath}
\usepackage{caption}
\usepackage{textcomp}
\usepackage[utf8]{inputenc}
\usepackage[toc,page]{appendix}
%\usepackage{subfig}
\usepackage{subcaption}
\usepackage[flushleft]{threeparttable}
\usepackage{booktabs}
\usepackage[T1]{fontenc}
\usepackage{microtype}
\usepackage{tikz}
\usepackage[europeanresistors]{circuitikz}
\usetikzlibrary{shapes, arrows, fit}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{cycle list/Dark2}
\usepgfplotslibrary{statistics}
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{2}
% UT Style
\usepackage{sectsty,textcase}
\usepackage{minitoc}
\usepackage{amsthm}
\usepackage{amsmath}
\usepackage{listings}
\usepackage{color}
\usepackage{float}
\usepackage{geometry}
\usepackage{fancyhdr}
%\usepackage[square,authoryear]{natbib}
\usepackage[pdftex,colorlinks=true]{hyperref}
\hypersetup{
colorlinks,
citecolor=black,
filecolor=black,
linkcolor=black,
urlcolor=black
}
\usepackage{wrapfig}
\usepackage{notes}
\usepackage{watermark}
\usepackage{epstopdf}
\usepackage{todonotes} %needed for todos
\usepackage{siunitx} %for Celsius degree symbol
% New Commands
\newcommand{\tbi}[1]{\textbf{\textit{#1}}}
\newcommand{\imp}[1]{\underline{\textit{#1}}}
\newcommand\tab[1][1cm]{\hspace*{#1}}
\usepackage{enumitem}
\let\svitem\item%
\def\mybox#1{\makebox[2cm][l]{\bfseries#1}}
\newenvironment{leftitemize}
{\renewcommand\item[1][$\bullet$]{\svitem[\mybox{##1}]}%
\begin{itemize}[leftmargin=\dimexpr2cm+\labelsep]}{\end{itemize}}
% Plot of graphs
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
编译后,我收到多个未定义的控制序列错误,但它们似乎并未指向真正的问题(见图)。
在这里您可以看到我的 .log 文件: https://drive.google.com/open?id=1JBDwYsNhxNRvZt6x7B6jIKM7l8mfOAyt
提前感谢您的帮助。
答案1
经过一些调试,我发现了问题所在。显然,使用包:\usepackage[utf8]{inputenc} 是导致我出现问题的原因。我不太清楚为什么会发生这种情况,但只要删除包,脚本就可以运行,图像就可以生成。