2
$\begingroup$

This was so much easier in Python (so much so that I'm considering going back to matplotlib for data analysis). But really, trying to figure out ROOT and Boost graph library and mathgl makes me want to die.

What I'm thinking for the short term is to somehow export my 2d array to a text file and then import that file into a numpy array as I already have that infrastructure coded. Then I'll use matplotlib to visualize the data.

In the long term, I'd like to learn the "standard way"to visualize data from c++ to add to my list of marketable skills. I've been scared away from Root by some of my particle physics friends, disgusted away from mathgl by a Linux snob and like how gnuplot looks but am turned off by the fact that it's command line operated. Is there nothing directly synonymous with matplotlib in c++ in functionality and ease of use?

$\endgroup$
9
$\begingroup$

There are a couple subtleties to your question that I think are important:

  • You're comparing an interpreted language (Python) to a compiled language (C++).
  • Most scientific and engineering software is developed with a heavy Linux (and UNIX) bias, and is not usually known for cross-platform compatibility or great user support (big libraries, of course, excepted)

If you really want to use a C++ library, you probably want something that has a CMake-based build system. PLplot is one such library that looks reputable and has a C++ interface (unfortunately, the others that seem to come up are ROOT and MathGL...).

However, given the points above, if using Cygwin or MinGW is going to drive you into a murderous rage, I'd stick with Python or a visualization program you could install from a binary (like Paraview or VisIt, for instance; other programs could also work). Here's why:

Interpreted languages are convenient for tweaking visualizations

The big advantage of doing your visualization in C++ is that you can append it to whatever C++ code you might be using for simulation work. That said, if you have to compile your code after every modification you make, it's going to make tweaking your visualizations that much more time-consuming. With an interpreted language, once the data is loaded, you can post-process and tweak visualizations on the command line. If you plot raw data and decide it might look better normalized, no problem; a few lines of code, and you can bring up a new plot in a minute or two without having to recompile.

Compiling scientific software on Windows is a pain

...because much of the time, whoever wrote it didn't use a cross-platform build system like CMake, so you either have to slog through and hack together a Makefile that works, or use Cygwin or MinGW to compile everything and hope that the software doesn't rely on Linux libraries (because after all, Cygwin is a POSIX compatibility layer). If a project uses CMake, it probably means that the developers have thought about these issues, and CMake will output the necessary build scripts to compile software with Visual Studio, which will make your life less painful. Otherwise, it's probably not worth the time and effort.

If you can install the visualization software you need from a binary, you don't have to worry about grappling with Visual Studio. There are at least two Python distributions I can think of that will supply Matplotlib (Continuum's Anaconda and Enthought Canopy) with a binary install of Python on multiple platforms. Paraview and VisIt are both powerful scientific visualization packages that, again, can be installed from binaries (they can also be built from source on Windows).

I don't think there is a "standard C++ way" to plot data

I haven't heard of a "standard C++ way" to plot data (it doesn't mean it doesn't exist); when I talk to data scientists, a lot of them stress how convenient and important it is to be fluent in an interpreted language like Python, R, or MATLAB because visualization and post-processing can be developed rapidly in those languages. Standard practice for a lot of fields is to dump data to some text format (column-delimited, CSV, HDF5, VTK, etc.) and then read in the data using one of those interpreted languages or a dedicated visualization program (like VisIt, Paraview, and for 2-D plots, gnuplot).

$\endgroup$
2
$\begingroup$

C++ does not have a standard library that contains the ability to generate plots (or, in fact, anything graphical). Nor does C++ have a system of packages with a package manager that allows you to import this functionality.

However, there are cross-platform libraries that facilitate what you want. The most widely used one, also available on Windows, is probably Qt. It will be a little bit more work than in Python to open a window and plot something, but it shouldn't be as difficult as with many of the other libraries you mention.

$\endgroup$
1
$\begingroup$

Well, for one, you can call gnuplot as a library. Pretty much every command you'd use at the prompt has a similarly-named API function.

$\endgroup$
  • 1
    $\begingroup$ Are you talking about this? ndevilla.free.fr/gnuplot $\endgroup$ – Hair of Slytherin Nov 11 '13 at 20:19
  • $\begingroup$ @KarstenChu: I believe that is what BillBarth is talking about. A labmate of mine has used that interface in the past. $\endgroup$ – Geoff Oxberry Nov 11 '13 at 21:38
  • 1
    $\begingroup$ Probably. I was speaking from memory. There's also this: suiri.tsukuba.ac.jp/~asanuma/gnuplot++ $\endgroup$ – Bill Barth Nov 11 '13 at 21:45
  • $\begingroup$ It looks like a lot of these projects are forgotten about or have gone by the wayside. I'd found the asanuma page and was fiddling with that, but it looks like I have to build it linux style and I'm a Windows guy. Using Cygwin is driving me to murderous rage. The idea behind these interfaces is that I'll be able to directly plot my data from the code I write in visual studio 12? $\endgroup$ – Hair of Slytherin Nov 12 '13 at 0:35
1
$\begingroup$

There is CImg, a header-only library that is fairly performant but not very tweakable. It is mainly about image processing, but it also offers some functions for drawing graphs and axes, albeit limited (you get the graph options you get, and that is it).

The biggest quirk with it is just getting used to the way the image is stored internally. The color channels are separated, so you've got contiguous bytes for blue, then green, then red. To output to a screen or file, you've got to interleave them back together. The sample code is good and makes it easy to figure things out.

I've used it (it can draw a few graphs fast enough to keep up with a live video stream at 60fps) but also look longingly at matplotlib and the like.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.