我有以下代码:
\documentclass[a4paper, landscape]{article}
\usepackage{amsmath}
\usepackage{pgfplots}
\usepackage{graphicx}
\usepackage{underscore}
\usepackage{adjustbox}
\usepackage{filecontents}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{adjustbox}{center, set height=\textheight}
\begin{tikzpicture}
\begin{axis}[
title={ Settings: ('1', '0') },
xlabel={ Frequency [kHz] },
ylabel={ Consumption [W] },
legend pos=outer north east,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
no markers,
width=24cm,
height=11cm,
cycle list name = color list
]
\addplot gnuplot [raw gnuplot] { plot 'data11200.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11201.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11202.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11203.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11204.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11205.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11206.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11207.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11208.csv' every 10};
\addplot gnuplot [raw gnuplot] { plot 'data11209.csv' every 10};
\legend{ 6,7,8,9,10,11,12,13,14,15 }
\end{axis}
\end{tikzpicture}
\end{adjustbox}
\end{document}
文件data11200.csv
如下所示:
ind,val
1200000.0,95.77487445833333
1300000.0,94.35378141666668
1400000.0,90.58904254166667
1500000.0,88.2311345
1600000.0,86.95179183333333
1700000.0,84.05458666666667
1800000.0,83.41422775
1900000.0,83.93314775
2000000.0,83.99366095833334
2100000.0,84.14217891666667
2200000.0,82.13892612500001
2300000.0,81.391646
2400000.0,81.5418625
2500000.0,84.38398554166666
其他文件基本相同,只是“正确”值略有不同。
问题是,当我尝试用编译此代码时lualatex -shell-escape
,我收到以下警告,而我得到的只是一个没有任何图的空网格。
Package pgfplots Warning: the current plot has no coordinates (or all have been filtered away)
Package pgfplots Warning: You have an axis with empty range (in direction y). Replacing it with a default range and clearing all plots.
我真的不知道第一次警告的原因是什么。
我可以看到,第二个警告告诉我,我应该明确地给他 y 轴的范围……但它可能会有很大的变化,所以我想自动完成。我知道,用table
这种pgfplots
方式是可能的
\addplot table [x=ind, y=val, col sep=comma] {data1.csv},
但我不太确定gnuplot
。那么,有可能吗?
您知道如何解决这个问题吗?
答案1
来自手册:
... plot gnuplot 命令使用外部程序 gnuplot 来计算坐标。结果坐标将写入文本文件,该文件将与 plot 文件一起绘制。
因此gnuplot
仅用于根据表达式计算坐标。绘图本身由 完成pgfplots
。
要仅绘制给定文件中的第 10 个坐标,data11200.csv
您可以使用
\addplot table[each nth point=10,col sep=comma] {data11200.csv};
代码:
\begin{filecontents*}{data11200.csv}
ind,val
1200000.0,95.77487445833333
1300000.0,94.35378141666668
1400000.0,90.58904254166667
1500000.0,88.2311345
1600000.0,86.95179183333333
1700000.0,84.05458666666667
1800000.0,83.41422775
1900000.0,83.93314775
2000000.0,83.99366095833334
2100000.0,84.14217891666667
2200000.0,82.13892612500001
2300000.0,81.391646
2400000.0,81.5418625
2500000.0,84.38398554166666
\end{filecontents*}
\documentclass[a4paper, landscape]{article}
\usepackage{pgfplots}
\usepackage{adjustbox}
\pgfplotsset{compat=1.13}
\begin{document}
\begin{adjustbox}{center, set height=\textheight}
\begin{tikzpicture}
\begin{axis}[
title={ Settings: ('1', '0') },
xlabel={ Frequency [kHz] },
ylabel={ Consumption [W] },
legend pos=outer north east,
xmajorgrids=true,
ymajorgrids=true,
grid style=dashed,
width=24cm,
height=11cm,
cycle list name = color list
]
\addplot table[each nth point=10,col sep=comma] {data11200.csv};
\legend{6}
\end{axis}
\end{tikzpicture}
\end{adjustbox}
\end{document}