我正在做一些探索模拟,我想展示图表来比较运行时算法之间的性能.
想到什么图书馆?如果我的教练很容易编译我的代码,我非常喜欢那些我喜欢的小版本.我检查了gdchart,但它似乎太沉重了.我只想要一个简单的xy时间轴图.
谷歌图表当然是不可能的,如果你读过这个类似的问题.
相关文章C++中的Scatter Plots.
Bil*_*nch 12
老实说,我和你在同一条船上.我有一个C++库,我想连接到图形实用程序.我最终使用了Boost Python和matplotlib.这是我能找到的最好的一个.
作为旁注:我也对许可证持谨慎态度.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();
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
105199 次 |
| 最近记录: |