C++ 中的散点图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/215110/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:46:52  来源:igfitidea点击:

Scatter Plots in C++

c++data-visualizationscatter-plot

提问by paxos1977

What is the best way to graph scatter plots in C++?

在 C++ 中绘制散点图的最佳方法是什么?

Do you write data to a file and use another tool? Is there a library like matplotlib in Python?

您是否将数据写入文件并使用其他工具?Python中有没有像matplotlib这样的库?

回答by freespace

I always write out data and then using gnuplotto create my graphs. It is by far the best way I have found of producing graphs in a variety of formats: eps, png, jpeg, xpm, you name it.

我总是写出数据,然后使用gnuplot创建我的图表。这是迄今为止我发现的以各种格式生成图形的最佳方式:eps、png、jpeg、xpm,等等。

gnuplotwill do scatter plot very easily. Provided the xand yvalues are in 2 space-separated columnss, then

gnuplot会很容易做散点图。如果xy值位于 2 个空格分隔的列中,则

plot "data.txt" using 1:2 

Will give you a quick scatter plot. Then you can adjust it and what not using other gnuplot commands.

会给你一个快速的散点图。然后您可以调整它以及不使用其他 gnuplot 命令的内容。

If you are involved in sciences, then learning gnuplotwill be very valuable to you. It kicks the crap out of doing excel plots for sure and it eases the task of making plots to include in papers.

如果你从事科学,那么学习gnuplot对你来说将是非常有价值的。它肯定可以消除做 excel 绘图的废话,并且简化了制作绘图以包含在论文中的任务。

回答by David Segonds

If you are looking for a C++ library rather than I independent plotting tool like gnuplot, I would consider the following:

如果您正在寻找 C++ 库而不是像 gnuplot 这样的独立绘图工具,我会考虑以下内容:

dislin seems to be the more interesting of the two. Here is a description extracted from the wikipedia article:

dislin 似乎是两者中更有趣的一个。这是从维基百科文章中提取的描述:

DISLIN is a high-level and easy to use plotting library developed by Helmut Michels at the Max Planck Institute in Katlenburg-Lindau, Germany. Helmut Michels currently works as a mathematician and Unix system manager at the computer center of the institute.

The DISLIN library contains routines and functions for displaying data as curves, bar graphs, pie charts, 3D-colour plots, surfaces, contours and maps. Several output formats are supported such as X11, VGA, PostScript, PDF, CGM, HPGL, SVG, PNG, BMP, PPM, GIF and TIFF.

DISLIN is available for the programming languages Fortran 77, Fortran 90/95 and C. Plotting extensions for the languages Perl, Python and Java are also supported for most operating systems. The current version of DISLIN is 9.4, released in October 2008. The first version 1.0 was released in December 1986.

The DISLIN software is free for non-commercial use.

DISLIN 是一个高级且易于使用的绘图库,由德国卡特伦堡-林道马克斯普朗克研究所的 Helmut Michels 开发。Helmut Michels 目前在研究所的计算机中心担任数学家和 Unix 系统经理。

DISLIN 库包含将数据显示为曲线、条形图、饼图、3D 彩色图、曲面、等高线和地图的例程和函数。支持多种输出格式,例如 X11、VGA、PostScript、PDF、CGM、HPGL、SVG、PNG、BMP、PPM、GIF 和 TIFF。

DISLIN 可用于 Fortran 77、Fortran 90/95 和 C 编程语言。大多数操作系统也支持 Perl、Python 和 Java 语言的绘图扩展。DISLIN 的当前版本是 9.4,于 2008 年 10 月发布。第一个版本 1.0 于 1986 年 12 月发布。

DISLIN 软件可免费用于非商业用途。

回答by dmckee --- ex-moderator kitten

Very heavy solution: you could link against ROOT, which will do just about anything you want:

非常繁重的解决方案:您可以链接ROOT,它几乎可以做您想做的任何事情:

  • runs on Mac, Windows and Linux
  • runs compiled or using the cint interperter
  • output to a file in encapsulated postscript, PDF, gif, png...
  • display to the screen using several different technologies
  • serialize the data in an internal format that can be manipulated later
  • 在 Mac、Windows 和 Linux 上运行
  • 运行编译或使用 cint interperter
  • 以封装的 postscript、PDF、gif、png 格式输出到文件...
  • 使用几种不同的技术显示到屏幕上
  • 以可以稍后操作的内部格式序列化数据

Sure, its a bit much for most people, but it does do exactly what you asked for. I use it because I know it and it is already on my machines becase I'm that kind of physicist.

当然,它对大多数人来说有点多,但它确实可以满足您的要求。我使用它是因为我知道它并且它已经在我的机器上,因为我是那种物理学家。

回答by paxos1977

Good old GNU, they have everything...

好老的 GNU,他们拥有一切......

http://directory.fsf.org/project/plotutils/

http://directory.fsf.org/project/plotutils/

回答by Konrad Rudolph

This is certainly not the best way but I usually write output files that can be read by Rand use this, along with an appropriate script, to plot the graphs.

这当然不是最好的方法,但我通常编写可由R读取的输出文件,并使用它以及适当的脚本来绘制图形。

回答by Dima

The problem here is that C++, unlike Java for example, does not have built-in GUI or graphics. If you want to generate graphs with C++ you would need to use a GUI library available for your OS. There are free GUI libraries, many cross-plaform such as Qt or GTK.

这里的问题是,与 Java 不同,C++ 没有内置的 GUI 或图形。如果要使用 C++ 生成图形,则需要使用适用于您的操作系统的 GUI 库。有免费的 GUI 库,许多跨平台的库,例如 Qt 或 GTK。

However, as other people have pointed out, the easiest thing for you to do would be to save the data into a text file, and use another program to generate the graph. gnuplot is definitely a good choice. It comes standard with most linux distros, and you get for Windows under cygwin.

但是,正如其他人所指出的,对您来说,最简单的方法是将数据保存到文本文件中,然后使用其他程序生成图形。gnuplot 绝对是一个不错的选择。它是大多数 linux 发行版的标准配置,您可以在 cygwin 下获得 Windows。

回答by Islam Yousry

Regards plotting in C++ for anyone who didn't do it yet. I will say what I did to plot Graphs in C++

向尚未使用 C++ 绘图的任何人致敬。我会说我是怎么用 C++ 绘制图形的

  1. Download the zipped file "gp443win32.zip" from http://sourceforge.jp/projects/sfnet_gnuplot/downloads/gnuplot/4.4.3/gp443win32.zip/

  2. Extract it in "C:\Gnuplot" then I read "C:\Gnuplot\gnuplot\README.Windows" and I got these information:

  3. I used Windows 7 ==> so you need to download "winhlp32.exe"... just search for it "winhlp32.exe Windows 7" in a search engine and go through the first link.

  4. Append to the "Path" Environment variable the path for binary folder which is "C:\Gnuplot\gnuplot\binary"

  5. then I shutdown my computer and open it again. After I found that it didn't sense the change in the environment variables :D

  6. you need now to write a sample code to test your plotting ability :) so you can visit this link http://code.google.com/p/gnuplot-cpp/source/browse/#svn%2Ftrunkto see the header file "gnuplot_i.hpp" and source file "example.cc".

  1. http://sourceforge.jp/projects/sfnet_gnuplot/downloads/gnuplot/4.4.3/gp443win32.zip/下载压缩文件“gp443win32.zip”

  2. 将它解压到“C:\Gnuplot”然后我读到“C:\Gnuplot\gnuplot\README.Windows”,我得到了这些信息:

  3. 我使用了 Windows 7 ==> 所以你需要下载“winhlp32.exe”...只需在搜索引擎中搜索它“winhlp32.exe Windows 7”并通过第一个链接。

  4. 将二进制文件夹的路径附加到“路径”环境变量,即“C:\Gnuplot\gnuplot\binary”

  5. 然后我关闭我的电脑并再次打开它。在我发现它没有感觉到环境变量的变化之后:D

  6. 您现在需要编写示例代码来测试您的绘图能力:) 这样您就可以访问此链接 http://code.google.com/p/gnuplot-cpp/source/browse/#svn%2Ftrunk以查看头文件“gnuplot_i.hpp”和源文件“example.cc”。

You will get many and many graphs, choose your appropriate graph, customize your core, and enjoy :)

您将获得许多图表,选择合适的图表,自定义您的核心,然后享受 :)

回答by Alex Coventry

If you're familiar with matplotlib, you can embedpython in C/C++ applications. Depending on what you want it for, this might be a quick solution.

如果您熟悉 matplotlib,则可以在 C/C++ 应用程序中嵌入python。根据您的需求,这可能是一个快速的解决方案。

回答by Kibbee

Chart Directorhas bindings for C++. I've used their .Net libraries, and I've been pretty happy with them. It's a pretty cheap library, and gives you the power to do all sorts of different charts.

Chart Director具有 C++ 的绑定。我用过他们的 .Net 库,我对他们很满意。这是一个非常便宜的库,让您能够制作各种不同的图表。