Plotting with exlib

The best is to start with an example of how to plot an inlib histogram with exlib. For that reconstruct the plotter_X11 example with :

    cd <path to exlib>
    cd examples/cpp
    ./build plotter_X11.cpp

you should see :


Contrary to an inlib example, here the build script is rather mendatory since you have to pass all the "-I" and "-L" flags in order to use some external packages. The build script is a little bit more complicated than the one of inlib, but we have tried to keep it readable. It uses the "use_external" scripts found under exlib/mgr to find flags of the needed external packages. For plotter_X11, the build script uses :


If having problem to compile one of the example because of "something not found" for a given external package, check/change the flags found in the related use script. Note that the comes also with the code of some common external packages (freetype2, expat, jpeg, png, zlib, zip, cfitsio), then if really in trouble with an external, you can build with the option "-standalone" that will ask the use scripts to compile and link with the code coming with the distribution.

    cd <path to exlib>
    cd examples/cpp
    ./build -standalone plotter_X11.cpp

You can have a look to plotter_X11.cpp and see that the code is rather simple and easy to customize...

// Copyright (C) 2010, Guy Barrand. All rights reserved.
// See the file exlib.license for terms.

#include <inlib/mem>
#include <inlib/random>

#include <exlib/X11/plotter>

#include <iostream>
#include <cstdlib>

int main(int,char**) {

#ifdef INLIB_MEM

  /// create and fill histogram : //////////////////////////
  inlib::histo::h1d h("Random Gauss",100,-5,5);
  inlib::random::gauss rg(0,1);
  for(unsigned int index=0;index<10000;index++) h.fill(rg.shoot(),1);

  /// plotting : ///////////////////////////////////////////
  exlib::X11::session x11(std::cout);
  if(!x11.display()) return EXIT_FAILURE;

  exlib::X11::plotter plotter(x11);
  if(!plotter.window()) return EXIT_FAILURE;

  plotter.bins_style(0).color = inlib::colorf::lightgrey();

  plotter.infos_style().font = inlib::sg::font_arialbd_ttf();
  plotter.infos_style().front_face = inlib::sg::winding_cw;
  plotter.infos_x_margin() = -0.01f; //percent of plotter width.
  plotter.infos_y_margin() = -0.01f; //percent of plotter height.



#ifdef INLIB_MEM

  return EXIT_SUCCESS;

Note that in order to build this program, it had not been needed to build and install some rather (complicated) "graphics / plotting / analysis / interpreter" package. All the externals are some quite standards ones (X11, OpenGL, freetype2) that are probably already installed on your machine and, if not, can be easily installed by using some installer tool coming with your machine (apt-get on a Linux, Macport on a Mac, etc...)