PLplotのexampleひどすww

PLplotのexample03があまりにもひどかった
https://plplot.svn.sourceforge.net/svnroot/plplot/trunk/examples/c++/x03.cc

ちなみにPLplotの使い方は https://sites.google.com/site/makeplplot/ がよくまとまっている。

PLplot自体はいいライブラリだと思うんだけど、C++bindingは"例が"ひどすぎる。
でもライブラリのインターフェイスを書きなおす気は起きないので
簡単に使える方法を模索。
例えば、使い方としてはplstreamを継承してしまうのはどうだろう?
(std::shared_ptrを使ってるのでC++11で)

#include<iostream>
#include<string>
#include<vector>
#include<memory>
#include<plstream.h>

class Plots : plstream {
public:
    Plots(int argc,const char** argv) {
        parseopts(&argc, argv, PL_PARSE_FULL);
        scolbg(255,255,255);
        scol0(15, 0, 0, 0);
        // sdev("aqt");  // AquaTerm
        init();
    }
    void plot(int num,
            std::vector<double>& ax,
            std::vector<double>& ay)
    {
        col0(15);
        env(-1.3,1.3,-0.3,1.3,1,1);
        lab("X", "Y", "y=x#u2#d");
        col0(1);
        wid(3);
        line(num,&ax[0],&ay[0]);
    }
};

int main(int argc,const char** argv) {
    std::shared_ptr<Plots> pls(new Plots(argc,argv));

    const int num = 30;
    std::vector<double> ax(num),ay(num);

    const double x_min=-1.0, x_max=1.0;
    for(int i=0;i<num;++i) {
        ax[i] = x_min+(x_max-x_min)/(num-1.0)*i;
        ay[i] = ax[i]*ax[i];
    }

    pls->plot(num,ax,ay);
    return 0;
}

少しはましかな?