C++ 在 Qt 中制作绘图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1491362/
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
Making plot in Qt
提问by Night Walker
回答by Nejat
I love QCustomPlot which is a Qt C++ library. It focuses on making good looking, publication quality 2D plots, graphs and charts and also has high performance for real-time visualization applications. You can get it here: http://www.qcustomplot.com/
我喜欢 QCustomPlot,它是一个 Qt C++ 库。它专注于制作美观、出版质量的 2D 绘图、图形和图表,并且对实时可视化应用程序也具有高性能。你可以在这里得到它:http: //www.qcustomplot.com/
回答by Sam Dutton
I strongly recommend Qwt.
我强烈推荐Qwt。
Qwt is a mature, well-documented library and, I think it's fair to say, the standard solution for implementing plots and other display and control widgets in Qt.
Qwt 是一个成熟的、有据可查的库,我认为可以公平地说,它是在 Qt 中实现绘图和其他显示和控制小部件的标准解决方案。
If you need 3D plots, try QwtPlot3D.
如果您需要 3D 绘图,请尝试QwtPlot3D。
回答by MadH
I'm using Qwt
for that. The trick is to use a step function (see last example by this link), and shift the data by 0.5, so that bars will be centered to ticks. Here is an example of what you can get with alpha blending and anti-aliasing enabled: my histogram.
Hope, you will do even better ;-)
我正在使用Qwt
它。诀窍是使用阶跃函数(请参阅此链接的最后一个示例),并将数据移动 0.5,以便柱线以刻度为中心。以下是启用 alpha 混合和抗锯齿后可以获得的示例:my histogram。希望,你会做得更好;-)
回答by poleguy
As an alternative to Qwt you might also consider qt-plotting-widgetwhich may be a simpler option.
作为 Qwt 的替代方案,您还可以考虑qt-plotting-widget,这可能是一个更简单的选择。
回答by Attila Tanyi
回答by Aaron Digulla
Qt has no support for plotting out of the box.
Qt 不支持开箱即用的绘图。
The most basic solution is to use QGraphicsView. Simply render your plot using the various items.
最基本的解决方案是使用QGraphicsView。只需使用各种项目渲染您的绘图。
Other than that, you can follow this thread. It contains a couple of pointer to plotting frameworks but I don't know how useful they are or whether they are still supported in Qt 4.x.
除此之外,您可以关注此线程。它包含几个指向绘图框架的指针,但我不知道它们有多大用处,也不知道 Qt 4.x 是否仍然支持它们。
回答by Darien Pardinas
QCustomPlot
is really easy to get started and there is plenty of Cartesian plot types you can do. Having said that, performance-wise it is not as good as other people say if you intend to plot large time series all at once. It internally uses a QMap
to store the data which means that for every data point you insert or remove when populating, there is going to be one allocation / release of memory to add the data point to the map. See this postfor more information.
QCustomPlot
非常容易上手,并且您可以执行很多笛卡尔绘图类型。话虽如此,如果您打算一次绘制大型时间序列,那么在性能方面不如其他人说的那么好。它在内部使用 aQMap
来存储数据,这意味着对于您在填充时插入或删除的每个数据点,都会分配/释放一次内存以将数据点添加到映射中。有关更多信息,请参阅此帖子。
Another thing I don't like is that even for simple plots it uses internally a struct QCPData
that stores 6 double values when you would normally need two (x
and y
). That is, it triples the amount of memory you need to display a time series.
我不喜欢的另一件事是,即使对于简单的绘图,它在内部使用一个结构QCPData
来存储 6 个双精度值,而您通常需要两个 (x
和y
)。也就是说,它将显示时间序列所需的内存量增加了三倍。