33

I am doing a little exploring simulation and I want to show the graphs to compare the performance among the algorithms during run-time.

What library comes to your mind? I highly prefer those that come small as I'd love if it's easy for my instructor to compile my code. I've checked gdchart but it seems to be too heavy. I just want a simple x-y sort of timeline graph.

Google chart is of course out of the question, in case you've read this similar question.


Related post Scatter Plots in C++.

nbro
  • 15,395
  • 32
  • 113
  • 196
syaz
  • 2,659
  • 6
  • 36
  • 44

4 Answers4

21

My favourite has always been gnuplot. It's very extensive, so it might be a bit too complex for your needs though. It is cross-platform and there is a C++ API.

Jon Cage
  • 36,366
  • 38
  • 137
  • 215
moinudin
  • 134,091
  • 45
  • 190
  • 216
13

Honestly, I was in the same boat as you. I've got a C++ Library that I wanted to connect to a graphing utility. I ended up using Boost Python and matplotlib. It was the best one that I could find.

As a side note: I was also wary of licensing. matplotlib and the boost libraries can be integrated into proprietary applications.

Here's an example of the code that I used:

#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();
    }
}
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
6

I've used this "portable plotter". It's very small, multiplatform, easy to use and you can plug it into different graphical libraries. pplot

(Only for the plots part)

If you use or plan to use Qt, another multiplatform solution is Qwt and Qchart

alvatar
  • 3,340
  • 6
  • 38
  • 50
5

Cern's ROOT produces some pretty nice stuff, I use it to display Neural Network data a lot.

Ed James
  • 10,385
  • 16
  • 71
  • 103
  • 3
    Though of course ROOT is neither a lightweight addition to your working environment, nor trivial to make use of. Still, I'm in particle physics, so use it almost exclusively. – dmckee --- ex-moderator kitten Feb 28 '11 at 00:42
  • 3
    "Criticisms of ROOT include its difficulty for beginners, as well as various aspects of its design and implementation. Frequent causes of frustration include extreme code bloat, heavy use of global variables, and a **perverse class hierarchy**." [Wikipedia](https://en.wikipedia.org/wiki/ROOT) Can attest to this. – Joseph Farah Feb 09 '19 at 06:35