c++ - CERN ROOT: Is is possible to plot pairs of x-y data points? -


i use cern root draw 2d graph of pairs of x-y datapoints possibly y-errorbars. know how draw histograms.

is possible cern root? if how?

also realize there may better libraries doing this. have been using gnuplot, unfortunately can't seem integrate c++ code, since can't find c/c++ gnuplot interface covers features , allows me send data in bidirectional manner - ie: both , gnuplot.

if have better alternative suggestion welcome.

there gnuplot iostream send data c++ gnuplot. within root, can use (as suggested others) tgraph, tgrapherrors, tgraphasymerrors.

edit:

the gnuplot iostream example homepage looks this. means once have data points either 1 vector of tuples or several vectors of floats, can send them gnuplot.

#include <vector> #include <cmath> #include <boost/tuple/tuple.hpp>  #include "gnuplot-iostream.h"  int main() {     gnuplot gp;     // create script can manually fed gnuplot later:     //    gnuplot gp(">script.gp");     // create script , feed gnuplot:     //    gnuplot gp("tee plot.gp | gnuplot -persist");     // or choose of options @ runtime setting gnuplot_iostream_cmd     // environment variable.      // gnuplot vectors (i.e. arrows) require 4 columns: (x,y,dx,dy)     std::vector<boost::tuple<double, double, double, double> > pts_a;      // can use separate container each column, so:     std::vector<double> pts_b_x;     std::vector<double> pts_b_y;     std::vector<double> pts_b_dx;     std::vector<double> pts_b_dy;      // use:     //   std::vector<std::vector<double> >     //   boost::tuple of 4 std::vector's     //   std::vector of std::tuple (if have c++11)     //   arma::mat (with armadillo library)     //   blitz::array<blitz::tinyvector<double, 4>, 1> (with blitz++ library)     // ... or of sort      for(double alpha=0; alpha<1; alpha+=1.0/24.0) {         double theta = alpha*2.0*3.14159;         pts_a.push_back(boost::make_tuple(              cos(theta),              sin(theta),             -cos(theta)*0.1,             -sin(theta)*0.1         ));          pts_b_x .push_back( cos(theta)*0.8);         pts_b_y .push_back( sin(theta)*0.8);         pts_b_dx.push_back( sin(theta)*0.1);         pts_b_dy.push_back(-cos(theta)*0.1);     }      // don't forget put "\n" @ end of each line!     gp << "set xrange [-2:2]\nset yrange [-2:2]\n";     // '-' means read stdin.  send1d() function sends data gnuplot's stdin.     gp << "plot '-' vectors title 'pts_a', '-' vectors title 'pts_b'\n";     gp.send1d(pts_a);     gp.send1d(boost::make_tuple(pts_b_x, pts_b_y, pts_b_dx, pts_b_dy));      return 0; } 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

php - How do you embed a video into a custom theme on WordPress? -