【发布时间】:2014-10-12 15:03:07
【问题描述】:
我尝试通过 system() 在 gnu plot 中显示我的数据。 我将一些示例值写入文件,然后尝试使用 gnuplot 显示它们。
我是这样写测试数据的:
void Dataset::writeDataSetToFile(){
QString filename="/Users/rogerwilco/Desktop/test/data.txt";
QFile file(filename);
if(file.open(QIODevice::WriteOnly))
{
QTextStream stream (&file);
stream << "1" << endl << "9" << endl << "15"<< endl;
}
file.close();
}
然后在主窗口中触发将数据写入文件并调用 Gnuplot 来显示图形:
void MainWindow::saveDataToFile(){
myData->writeDataSetToFile();
}
void MainWindow::showGraph() {
system("/usr/local/bin/gnuplot \'/Users/rogerwilco/Desktop/test/plotter\'");
}
我收到此错误消息:
“/Users/rogerwilco/Desktop/test/plotter”,第 22 行:警告:跳过不可读的文件“data.txt”“/Users/rogerwilco/Desktop/test/plotter”,第 22 行:无数据在情节中
gnuplot 的脚本如下所示:
reset
n=100 #number of intervals
max=100.0 #max value
min=0.0 #min value
width=(max-min)/n #interval width
#function used to map a value to the intervals
hist(x,width)=width*floor(x/width)+width/2.0
#set term png #output terminal and file
set output "histogram.png"
set xrange [min:max]
set yrange [0:]
#to put an empty boundary around the
#data inside an autoscaled graph.
set offset graph 0.05,0.05,0.05,0.0
set xtics min,(max-min)/5,max
set boxwidth width*0.9
set style fill solid 0.5 #fillstyle
set tics out nomirror
set xlabel "x"
set ylabel "Frequency"
#count and plot
plot "data.txt" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb"green" notitle
出现错误的第 22 行是最后一行。 但是,如果我自己使用 shell 与
gnuplot 'plotter'
它有效。
为什么当我在终端中手动输入命令时它会起作用,而当我通过 system() 执行它时却不起作用?
系统:
- Qt 5.3.2
- Mac OS X 10.9.5
- gnuplot 4.6.6 通过自制软件
- AquaTerm 1.1.1 通过自制clang 64位
【问题讨论】:
-
Galik,感谢您的建议。你说的对。我需要在最后一行添加整个路径: plot "/Users/rogerwilco/Desktop/test/data.txt" u (hist($1,width)):(1.0) smooth freq w boxes lc rgb"绿色”无标题。如果您事后考虑一下,这很合乎逻辑... :-D
-
你想写下答案以便将其标记为已完成吗?
-
只是提示:gnuplot 知道命令
pwd。所以,如果有这样的问题,pwd 可以帮助调试。 -
@ChrisStratton 请将此添加为答案。
-
@ChrisStratton 不要忘记发布您的答案......