Gnuplot_i.hpp C++接口绘制局部变量而不是文件
Gnuplot_i.hpp C++ interface plot local variables instead of a file
我一直在使用Gnuplot_I.hpp c++接口,它允许你在c ++程序中使用gnuplot。它运行良好,除了我似乎无法控制绘图符号、颜色和其他一些重要的绘图功能。下面的代码片段说明了这个问题:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <iomanip> //io format setw(space)
#include "spline.h"
#include "gnuplot_i.hpp" //Gnuplot class
//
using namespace std;
int main(int argc, char** argv) {
//
vector<double> X(5), Y(5);
X[0]=0.1;
X[1]=0.4;
X[2]=1.2;
X[3]=1.8;
X[4]=2.0;
Y[0]=0.1;
Y[1]=0.7;
Y[2]=0.6;
Y[3]=1.1;
Y[4]=0.9;
//demoFile two colums 6 spaces apart
for (int i = 0; i < 5; ++i ) {
demoFile << std::setw(6) << X[i];
demoFile << std::setw(6) << Y[i];
demoFile << 'n';
}
demoFile.close();
//
Gnuplot g1("");
//
g1.reset_plot();
cout << endl << endl << "*** user-defined lists of points (x,y)" << endl;
g1.set_grid();
g1.set_pointsize(4.0);
g1.cmd("set term wxt font ',14';set xtics font 'Times-Roman, 14';
set ytics font 'Times-Roman, 14'");
//
g1.cmd("plot 'plotfile.txt' with points pointtype 7 pointsize 2 lc 'red'");
g1.set_style("points").plot_xy(X,Y,"Original");
最后一个绘图命令允许您绘制 X,Y 局部向量变量,但我无法设置点的符号或颜色。有一个set_style命令,但这不适用于设置一些重要的情节特征。您可以使用上面的 cmd(( 命令,该命令允许允许允许这些重要功能的"带有点的点类型 7 点大小 2 lc '红色'"字符串。问题是命令字符串似乎没有办法合并局部向量变量 X 和 Y。命令字符串仅识别强制您在打印之前输出到文件的文件参数。我尝试格式化 gprintf 和 sprintf 字符串以识别局部变量 X 和 Y 但没有成功。有没有人解决了这个问题?
gnuplot_i.hpp 中的 plot_xy(( 例程将 X 和 Y 向量写入临时文件,然后告诉 gnuplot 绘制该文件。 您可以执行完全相同的操作,除了通过g1.cmd
发出完整的 gnuplot plot 命令,其中包含您喜欢的所有样式规范,如您在脚本中所示。 那么问题到底是什么呢?
除 plot_xy((:
std::string name = create_tmpfile(tmp);
for (unsigned int i = 0; i < x.size(); i++)
tmp << x[i] << " " << y[i] << std::endl;
tmp.flush();
tmp.close();
plotfile_xy(name, 1, 2, title);
相关文章:
- 使用的未初始化局部变量'Quick'
- 修复未初始化的局部变量错误
- 局部变量保留函数中的值
- 如何使用 C++ 中的继承函数访问派生类中的局部变量
- 将引用分配给局部变量,如果局部变量超出范围,它会超出范围吗?
- Gnuplot_i.hpp C++接口绘制局部变量而不是文件
- 如何在函数外部访问函数中局部变量的值?
- 赋予全局变量而不是局部变量优先级的函数 - (异常行为)
- C++中静态方法的局部变量范围
- 未初始化的局部变量错误甚至认为我初始化了它(C++)
- 离开范围后如何保护局部变量的值?
- 局部变量名称冲突
- C++ lambda:如何'freeze'局部变量的值?
- 我应该使我的局部变量常量还是可移动的
- 获取具有静态局部变量的绑定/推断捕获 lambda 的函数指针
- 全局和局部变量初始化与 constexpr 的差异背后的基本原理
- 返回对局部变量 - C++ 的引用
- 是否可以影响 C++ 中回调函数的局部变量?
- 警告 C4101 未引用的局部变量
- C++,静态局部变量(方法)与全局(文件)变量有什么区别