I used Qwt some time back. It's a library on top of Qt which provides a number of very useful plotting tools. Beware of Qt licensing fees if this is actually a commercial project.
当我在学校的时候,我问过我的教授类似的问题,他说 C++ 并不是真正用于制作数据图之类的。他没有提出任何建议,但话又说回来,他更多的是一名嵌入式系统开发人员,并且没有将 C++ 用于科学计算应用程序。他的建议是用 C++ 进行所有数据处理,将结果保存在某个地方,然后使用 Python 或 R 导入结果,然后在那里进行数据分析。另一种选择是您可以使用 R 包 Rcpp 包。它允许您在 R 脚本或 Markdown 中编写 C++ 函数。 rcpp 包
I asked my professor similar questions when I was in school and he said C++ isn't really used for making plots of data and such. He didn't have any suggestions but then again he was more of an embedded systems developer and was not using C++ for scientific computing applications. His suggestion was to do all the data crunching in C++, save the results somewhere, and use Python or R to import the results, and then do the data analysis there. Another alternative is you could use the R package Rcpp package. It allows you to write C++ functions inside of an R script or a markdown. rcpp package
This answer may be useful for people like me who shifted from MATLAB (or some other well-developed scientific programming tools) to C++ (A primitive programming language).
Plotting is a bit tricky job in C++, as there is no default plotting library available in any C++ IDE. However, there are many libraries available online for making plotting possible in C++. Some plotting tools like Gnuplot, PPlot, etc are already mentioned in the above answers, however, I have listed one by one with relevant examples,
Koolplot a simple, elegant and easy to use tool for 2D plotting and may not be enough for your requirement. An example excerpt taken from the website is shown below, you can find more examples and the process of linking it with C++ IDE here.
GNUPlot, is a very robust opensource tool for plotting, with the help of an interface called Gnuplot-iostream interface, calling the gnuplot commands from C++ is very easy process. If somebody is already experienced plotting in gnuplot and have to use C++ for their programming, then this interface is very useful. Or if you want to create your own interface, this is the information provided in here will be very useful. The process of linking this interface is very easy, just install gnuplot in your system and then link the include directory and lib directory of gnuplot to C++ IDE, and then you are ready to go. Examples on how to use Gnuplot from C++ using gnuplot-iostream interface are given here, an excerpt of sample example is posted below.
MATLAB (Yes, I am not kidding MATLAB can be called from C++) If you are familiar with MATLAB, you can get the same functionality in C++ by calling, functions/toolboxes from MATLAB and vice versa. Since MATLAB is commercial software, first you have to acquire a license (this is very costly). If you have an installed MATLAB software, then use the engine.h file and link the necessary MATLAB library files to C++ IDE, then the process is outright simple. A detailed step-by-step process of linking Matlab to Visual Studio c++ is provided here and here. An example code is given here, an excerpt of an example is given below:
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "engine.h"
#define BUFSIZE 256
int main()
{
Engine *ep;
mxArray *T = NULL, *result = NULL;
char buffer[BUFSIZE+1];
double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 };
if (!(ep = engOpen(""))) {
fprintf(stderr, "\nCan't start MATLAB engine\n");
return EXIT_FAILURE;
}
T = mxCreateDoubleMatrix(1, 10, mxREAL);
memcpy((void *)mxGetPr(T), (void *)time, sizeof(time));
engPutVariable(ep, "T", T);
engEvalString(ep, "D = .5.*(-9.8).*T.^2;");
engEvalString(ep, "plot(T,D);");
engEvalString(ep, "title('Position vs. Time for a falling object');");
engEvalString(ep, "xlabel('Time (seconds)');");
engEvalString(ep, "ylabel('Position (meters)');");
printf("Hit return to continue\n\n");
fgetc(stdin);
printf("Done for Part I.\n");
mxDestroyArray(T);
engEvalString(ep, "close;");
buffer[BUFSIZE] = '\0';
engOutputBuffer(ep, buffer, BUFSIZE);
while (result == NULL) {
char str[BUFSIZE+1];
printf("Enter a MATLAB command to evaluate. This command should\n");
printf("create a variable X. This program will then determine\n");
printf("what kind of variable you created.\n");
printf("For example: X = 1:5\n");
printf(">> ");
fgets(str, BUFSIZE, stdin);
engEvalString(ep, str);
printf("%s", buffer);
printf("\nRetrieving X...\n");
if ((result = engGetVariable(ep,"X")) == NULL)
printf("Oops! You didn't create a variable X.\n\n");
else {
printf("X is class %s\t\n", mxGetClassName(result));
}
}
printf("Done!\n");
mxDestroyArray(result);
engClose(ep);
return EXIT_SUCCESS;
}
Python, people like questioner (who are familiar with matplotlib tool in Python). A very elegant interface is available to call python from C++. a simple example may look like this (source) and the matlabplotcpp.h is available here.
If you don't want to use it then I liked plplot when I used it: http://plplot.sourceforge.net/ . The canvas to plplot can be put into gtk+ frame too if you want to add buttons to your plot.
发布评论
评论(6)
我曾经使用过Qwt。它是 Qt 之上的一个库,提供了许多非常有用的绘图工具。如果这实际上是一个商业项目,请注意 Qt 许可费用。
I used Qwt some time back. It's a library on top of Qt which provides a number of very useful plotting tools. Beware of Qt licensing fees if this is actually a commercial project.
当我在学校的时候,我问过我的教授类似的问题,他说 C++ 并不是真正用于制作数据图之类的。他没有提出任何建议,但话又说回来,他更多的是一名嵌入式系统开发人员,并且没有将 C++ 用于科学计算应用程序。他的建议是用 C++ 进行所有数据处理,将结果保存在某个地方,然后使用 Python 或 R 导入结果,然后在那里进行数据分析。另一种选择是您可以使用 R 包 Rcpp 包。它允许您在 R 脚本或 Markdown 中编写 C++ 函数。 rcpp 包
I asked my professor similar questions when I was in school and he said C++ isn't really used for making plots of data and such. He didn't have any suggestions but then again he was more of an embedded systems developer and was not using C++ for scientific computing applications. His suggestion was to do all the data crunching in C++, save the results somewhere, and use Python or R to import the results, and then do the data analysis there. Another alternative is you could use the R package Rcpp package. It allows you to write C++ functions inside of an R script or a markdown. rcpp package
这个答案对于像我这样从 MATLAB(或其他一些成熟的科学编程工具)转向 C++(一种原始编程语言)的人来说可能很有用。
在 C++ 中绘图是一项有点棘手的工作,因为任何 C++ IDE 中都没有可用的默认绘图库。然而,有许多在线库可以使 C++ 中的绘图成为可能。上面的答案中已经提到了一些绘图工具,例如 Gnuplot、PPlot 等,但是我已经一一列出了相关示例,
GNUPlot,是一个非常强大的开源绘图工具,借助名为 Gnuplot-iostream 接口,从 C++ 调用 gnuplot 命令是非常简单的过程。如果有人已经有 gnuplot 绘图经验并且必须使用 C++ 进行编程,那么这个接口非常有用。或者,如果您想创建自己的界面,此处提供的信息将非常有用。链接这个接口的过程非常简单,只需在你的系统中安装gnuplot,然后将gnuplot的include目录和lib目录链接到C++ IDE,然后就可以开始了。 这里给出了如何使用 gnuplot-iostream 接口在 C++ 中使用 Gnuplot 的示例,摘录下面发布了示例示例。
MATLAB (是的,我不是开玩笑 MATLAB 可以从 C++ 调用)如果您熟悉 MATLAB,您可以通过从 MATLAB 调用函数/工具箱在 C++ 中获得相同的功能,反之亦然。由于 MATLAB 是商业软件,因此首先您必须获得许可证(这是非常昂贵的)。如果您安装了 MATLAB 软件,然后使用
engine.h
文件并将必要的 MATLAB 库文件链接到 C++ IDE,那么该过程非常简单。提供了将 Matlab 链接到 Visual Studio c++ 的详细分步过程 此处和此处。这里给出了示例代码,示例摘录如下:(来源)
Python,人们喜欢提问者(熟悉的人)使用 Python 中的 matplotlib 工具)。有一个非常优雅的接口可以从 C++ 调用 python。一个简单的示例可能如下所示(源)
matlabplotcpp.h
可在此处获取。<前><代码>#include“matplotlibcpp.h”
命名空间 plt = matplotlibcpp;
int main() {
plt::绘图({1,3,2,4});
plt::显示();
}
This answer may be useful for people like me who shifted from MATLAB (or some other well-developed scientific programming tools) to C++ (A primitive programming language).
Plotting is a bit tricky job in C++, as there is no default plotting library available in any C++ IDE. However, there are many libraries available online for making plotting possible in C++. Some plotting tools like Gnuplot, PPlot, etc are already mentioned in the above answers, however, I have listed one by one with relevant examples,
GNUPlot, is a very robust opensource tool for plotting, with the help of an interface called Gnuplot-iostream interface, calling the gnuplot commands from C++ is very easy process. If somebody is already experienced plotting in gnuplot and have to use C++ for their programming, then this interface is very useful. Or if you want to create your own interface, this is the information provided in here will be very useful. The process of linking this interface is very easy, just install gnuplot in your system and then link the include directory and lib directory of gnuplot to C++ IDE, and then you are ready to go. Examples on how to use Gnuplot from C++ using gnuplot-iostream interface are given here, an excerpt of sample example is posted below.
MATLAB (Yes, I am not kidding MATLAB can be called from C++) If you are familiar with MATLAB, you can get the same functionality in C++ by calling, functions/toolboxes from MATLAB and vice versa. Since MATLAB is commercial software, first you have to acquire a license (this is very costly). If you have an installed MATLAB software, then use the
engine.h
file and link the necessary MATLAB library files to C++ IDE, then the process is outright simple. A detailed step-by-step process of linking Matlab to Visual Studio c++ is provided here and here. An example code is given here, an excerpt of an example is given below:(source)
Python, people like questioner (who are familiar with matplotlib tool in Python). A very elegant interface is available to call python from C++. a simple example may look like this (source) and the
matlabplotcpp.h
is available here.我再次推荐 gnuplot。
如果你不想使用它,那么我在使用它时喜欢 plplot: http://plplot.sourceforge.net/ 。如果您想向绘图添加按钮,也可以将 plplot 的画布放入 gtk+ 框架中。
也就是说,我很快就回到了 gnuplot。
I again would recommend gnuplot.
If you don't want to use it then I liked plplot when I used it: http://plplot.sourceforge.net/ . The canvas to plplot can be put into gtk+ frame too if you want to add buttons to your plot.
That said, I returned to gnuplot before too long.
您是否尝试过使用 Gnuplot ?还提供 C++ 接口。
Have you tried using Gnuplot? A C++ interface is also available.
有GPL库MathGL,它是用C++编写的,具有Python/C/Fortran等接口。它也可以制作很多 3D 绘图。
There is GPL library MathGL which is written in C++ and have interfaces to Python/C/Fortran and so on. It can make a lot of 3D plots too.