2009-04-19 148 views
22

我在做一個小小的探索模擬,我想展示圖表來比較運行時算法間的性能。用C++繪製圖形和圖表的自由簡單方法?

你想到什麼庫?如果我的教師很容易編譯我的代碼,我非常喜歡那些像我喜歡的那樣小的東西。我檢查了gdchart,但它似乎太重了。我只想要一個簡單的x-y時間軸圖。

如果您已閱讀this類似問題,Google圖表當然不會出現問題。


Related post Scatter Plots in C++

+0

Windows,但我真的更喜歡跨平臺,因爲我大部分時間在Linux上編寫代碼,而我的教師使用Windows。 – syaz 2009-04-19 14:17:23

+0

檢查http://stackoverflow.com/questions/215110/scatter-plots-in-c/40612951#40612951 – SAAD 2016-11-15 14:57:04

回答

12

我最喜歡的一直是gnuplot。這是非常廣泛的,所以它可能有點太複雜,但您的需求。它是跨平臺的,有a C++ API

6

我已經使用這個「便攜式繪圖儀」。它非常小,多平臺,易於使用,您可以將其插入不同的圖形庫。 pplot

(僅適用於部分地塊)

如果您使用或計劃使用Qt,另一種多平臺解決方案是QwtQchart

+0

這看起來很有希望,顯示的例子確實比gdchart更簡單。 – syaz 2009-04-19 14:24:49

10

老實說,我是在同一條船上,你。我有一個C++庫,我想連接到一個圖形工具。我結束了使用Boost Pythonmatplotlib。這是我能找到的最好的一個。

作爲一個方面說明:我也很謹慎的授權。 matplotlib和boost庫可以集成到專有應用程序中。

下面是我使用的代碼示例:

#include <boost/python.hpp> 
#include <pygtk/pygtk.h> 
#include <gtkmm.h> 

using namespace boost::python; 
using namespace std; 

// This is called in the idle loop. 
bool update(object *axes, object *canvas) { 
    static object random_integers = object(handle<>(PyImport_ImportModule("numpy.random"))).attr("random_integers"); 
    axes->attr("scatter")(random_integers(0,1000,1000), random_integers(0,1000,1000)); 
    axes->attr("set_xlim")(0,1000); 
    axes->attr("set_ylim")(0,1000); 
    canvas->attr("draw")(); 
    return true; 
} 

int main() { 
    try { 
     // Python startup code 
     Py_Initialize(); 
     PyRun_SimpleString("import signal"); 
     PyRun_SimpleString("signal.signal(signal.SIGINT, signal.SIG_DFL)"); 

     // Normal Gtk startup code 
     Gtk::Main kit(0,0); 

     // Get the python Figure and FigureCanvas types. 
     object Figure = object(handle<>(PyImport_ImportModule("matplotlib.figure"))).attr("Figure"); 
     object FigureCanvas = object(handle<>(PyImport_ImportModule("matplotlib.backends.backend_gtkagg"))).attr("FigureCanvasGTKAgg"); 

     // Instantiate a canvas 
     object figure = Figure(); 
     object canvas = FigureCanvas(figure); 
     object axes = figure.attr("add_subplot")(111); 
     axes.attr("hold")(false); 

     // Create our window. 
     Gtk::Window window; 
     window.set_title("Engineering Sample"); 
     window.set_default_size(1000, 600); 

     // Grab the Gtk::DrawingArea from the canvas. 
     Gtk::DrawingArea *plot = Glib::wrap(GTK_DRAWING_AREA(pygobject_get(canvas.ptr()))); 

     // Add the plot to the window. 
     window.add(*plot); 
     window.show_all(); 

     // On the idle loop, we'll call update(axes, canvas). 
     Glib::signal_idle().connect(sigc::bind(&update, &axes, &canvas)); 

     // And start the Gtk event loop. 
     Gtk::Main::run(window); 

    } catch(error_already_set) { 
     PyErr_Print(); 
    } 
} 
+1

你會碰巧有一個簡單的例子說明你是如何做到這一點的,我會非常感興趣的發現。 – 2012-11-27 00:36:28

+1

@ZamfirKerlukson:http://blog.wlynch.cx/2009/11/03/Matplotlib/ – 2012-11-29 01:35:56

4

Cern的ROOT產生了一些非常不錯的東西,我用它來顯示神經網絡數據很多。