GNUPlotCPP - a tool for creating function plots from C++ code

DSP, Plugin and Host development discussion.
RELATED
PRODUCTS

Post

i have written a little tool that allows to create function- and data plots directly from C++ in a way similar to languages like MatLab/Octave, Mathematica, etc. it's actually a C++ code interface to GNUPlot, so what can and what can't be done is by and large determined by the feature set of GNUPlot. here it is:

http://www.rs-met.com/open_source/GNUPlotCPP.zip

it still needs some cleaning up of the code and extension of the user-manual and maybe support of other IDEs and platforms (at the moment, it supports visual studio 2015 on winodws), so consider this as a pre-release . but i think, it's already useful. to use it, just follow the instructions in the user manual (in the "Preliminaries" section) for setting everything up and then launch the visual studio solution and build-and-run the project. this will create a couple of demo plots, one after another (when you close one, the next will be opened).

consider the code public domain.
Last edited by Music Engineer on Fri Oct 30, 2015 5:51 pm, edited 1 time in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Thank you

This is really great. I thought of doing it as well at some point, but gave up at the command line.

Post

I would like to use it, but I don't have Visual Studio anymore. Can you offer a compiled version?

Post

camsr wrote:I would like to use it, but I don't have Visual Studio anymore. Can you offer a compiled version?
you should not need a compiled version, just add the GNUPlotter.h and GNUPlotter.cpp files to your own project and include the .h file whereever you need the plotting functionality within your code. so far, i didn't test it with any other compiler though.

...hmm - i'm not sure, i understand you right - do you want a .lib file to be used along with .h file? are you using GCC? CodeBlocks? maybe just try to compile the files there. IIRC, i didn't use anything microsoft compiler specific, so it might just work. otherwise, i may look into creating a CodeBlocks project as well.
Last edited by Music Engineer on Fri Oct 30, 2015 1:03 am, edited 1 time in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Mayae wrote:Thank you

This is really great. I thought of doing it as well at some point, but gave up at the command line.
thank you. yes - the GNUPlot commandline syntax itself has a rather non negligible learning curve. for creating more elaborate or customized plots, it's probably unavoidable to learn it at least partially - or at least, look it up once and write a convenience function for the particular type of plot one wants to (routinely) create, and then forget it again. some such convenience functions for very common tasks are already built in, but for more specific tasks, users may want to write their own.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Music Engineer wrote:
camsr wrote:I would like to use it, but I don't have Visual Studio anymore. Can you offer a compiled version?
you should not need a compiled version, just add the GNUPlotter.h and GNUPlotter.cpp files to your own project and include the .h file whereever you need the plotting functionality within your code. so far, i didn't test it with any other compiler though.

...hmm - i'm not sure, i understand you right - do you want a .lib file to be used along with .h file? are you using GCC? CodeBlocks? maybe just try to compile the files there. IIRC, i didn't use anything microsoft compiler specific, so it might just work. otherwise, i may look into creating a CodeBlocks project as well.
Sorry, I didn't understand what exactly it was. So it's an interface for GNUPlot?

Post

camsr wrote:Sorry, I didn't understand what exactly it was. So it's an interface for GNUPlot?
yes. if you download the archive, there's a folder "Documentation" where you find a UserManual.pdf file (along with the LaTeX "source code"). in this manual, it's explained in more detail

edit: it's basically a way to directly create plots from your usual C++ programming environment. like in matlab, where you can just write

Code: Select all

plot(x, y);
anywhere in your code and your environment shows you a window that plots an y-array against an x-array. with GNUPlotCPP, you can do similar things directly from anywhere in your C++ code. this is useful for debugging and experimentation.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

If it's easier than using fortran in octave, then it's a winner :)

Post

Having plots is always great (which is why I always start my DSP code with Python interfaces).

Post

camsr wrote:If it's easier than using fortran in octave, then it's a winner :)
fortran in octave? i don't know about this. i just know that octave uses GNUPlot as well for its plotting functions. actually, the idea behind it is that the user can write their own convenience functions for particular types of plots which are then very easy to use - in the simplest case, it should result in just one line of code to create a plot in client code. for example, consider the matlab function "zplane" which plots the poles and zeros of a filter in the z-plane:

http://de.mathworks.com/help/signal/ref/zplane.html

in the Demos.cpp file, there's a demo "demoPoleZeroPlotZ()" which just creates some arbitrary poles and zeros and then calls a function "poleZeroPlot". this poleZeroPlot function can be considered as such a convenience function, (partially) mimicking the functionality of matlab's zplane. it is not part of the GNUPlotter class itself, because it is a very (DSP) domain specific function and i want to keep the class lean and general. when you have a polynomial root finder at your disposal, you could also write a similar function on top of the existing one that doesn't take poles and zeros as input but raw filter coefficient arrays. the idea is that, for each particular application domain, the user can write a set of appropriate domain specific plotting functions on top of the GNUPlotter class which are then very easy to use. as another example, the "heatmap" example (see the manual) could be easily extended to plot spectrograms similar to matlab's

http://de.mathworks.com/help/signal/ref ... ogram.html

...assuming, of course, you have all the STFT stuff in place to compute the actual spectrogram.
Last edited by Music Engineer on Fri Oct 30, 2015 4:02 pm, edited 1 time in total.
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Miles1981 wrote:Having plots is always great (which is why I always start my DSP code with Python interfaces).
i was formerly prototyping in octave mainly because of plotting requirements during research. but i'm happy to drop that now and start directly writing C++ code. :D
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

That's because you didn't use Python at the time :p Octave is a pain...

Post

Miles1981 wrote:Octave is a pain...
yes - all the IDEs for it, i have tried so far, kinda suck compared to matlab - at least, that was the case last time i checked. which is why i'm considering to purchase a matlab license. but i can afford only the home-use (non-professional) one and i'm not sure, if that still applies to me. :scared: maybe, i should give python a shot. but i would have to learn a new language. but python seems popular generally, so it might be worth it. hmm...
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post

Definitely. It doesn't try to be Matlab (without being Matlab, same for scilab, they are not 100% compatible with Matlab) and the community behind may be stronger than octave's.
And really easy to learn. There are tables to check the equivalent to Matlab, so really easy to move.

Post

Miles1981 wrote:Definitely. It doesn't try to be Matlab (without being Matlab, same for scilab, they are not 100% compatible with Matlab) and the community behind may be stronger than octave's.
And really easy to learn. There are tables to check the equivalent to Matlab, so really easy to move.
that sounds good. for me, the most important thing would be to have a convenient IDE, where i can see all my variables/arrays/matrices/objects, inspect them, plot them easily (like: right-click on an array -> context-menu -> select "plot") etc. integrated with a good code editor and commandline interface. well, yeah, basically, all the good stuff, that matlab provides. is there such a thing for python?

MatLab/Octave on the other hand, has the big advantage, that most of the academic research and educational code is written in that language. julius smith's books, the DAFX book, the orfanidis filter designs, etc. - they all use matlab/octave for their code. that's a BIG plus
My website: rs-met.com, My presences on: YouTube, GitHub, Facebook

Post Reply

Return to “DSP and Plugin Development”