Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use gnuplot from C++?

Tags:

gnuplot

I want to plot some graphs with (x,y) points which is generated from a C++ programme. I can successfully plot these data from gnuplot command from a terminal.

But I want to plot the same thing from a C++ programme, is this thing possible in ubuntu 16.04 lts ?

like image 357
Bapi Avatar asked Aug 15 '17 15:08

Bapi


3 Answers

Sure, just install gnuplot using standard package command:

sudo apt-get update
sudo apt-get install gnuplot

After that you just need to integrate gnuplot iostream header which is an interface for gnuplot from C++:

#include "gnuplot-iostream.h"

This header is not included when you install gnuplot but can be found here. Here you have an example link of iostream for reference: iostream example code C++

like image 77
hackela Avatar answered Nov 17 '22 04:11

hackela


I am adding an answer since I cannot comment. As hackela said you can install gnuplot, then you can install gnuplot-iostream from aptitude instead of dowloading manually the header file, with this command:

sudo apt-get install libgnuplot-iostream-dev
like image 28
Dundo Avatar answered Nov 17 '22 02:11

Dundo


Another option: C++ lib matplotplusplus is actually sending drawing commands to GnuPlot. It provides an API similar to python matplotlib. It is available in C++ package manager vcpkg.

like image 40
Ying Dai Avatar answered Nov 17 '22 02:11

Ying Dai