#ifndef PLOTERRFUNC_H #define PLOTERRFUNC_H #include #include #include #include class PlotErrFunc { struct Entry { std::string name; K::Statistics stats; Entry(const std::string& name, const K::Statistics& stats) : name(name), stats(stats) {;} }; std::vector entries; std::vector lines; K::Gnuplot gp; K::GnuplotPlot gplot; //std::vector colors = {"#000000", "#ff0000", "#00bb00", "#0000ff"}; std::vector colors = {"#000000", "#999999", "#0000ff", "#9999ff"}; std::string codeFile; public: /** ctor with x-axis label */ PlotErrFunc(const std::string& xLabel, const std::string& yLabel) { gplot.setLabelX(xLabel); gplot.setLabelY(yLabel); } /** add one curve */ void add(const std::string name, const K::Statistics stats) { entries.push_back(Entry(name, stats)); K::GnuplotPlotElementLines* gpel = new K::GnuplotPlotElementLines(); gpel->setTitle(name); gpel->setLineWidth(2); lines.push_back(gpel); gplot.add(gpel); } void clear() { entries.clear(); } K::Gnuplot& getGP() { return gp; } void writeCodeTo(const std::string& file) { this->codeFile = file; } /** plot all curves */ void plot() { gp << "set grid\n"; for (size_t i = 0; i < entries.size(); ++i) { const Entry e = entries[i]; K::GnuplotPlotElementLines* line = lines[i]; line->clear(); //line.setTitle(e.name); line->setColorHex(colors[i]); // 0 - 80% for (int i = 0; i <= 85; i+= 5) { const float q = i / 100.0f; const float y = e.stats.getQuantile(q); K::GnuplotPoint2 gp(y, q*100); line->add(gp); } } gp.draw(gplot); if (codeFile != "") { std::ofstream out(codeFile); out << gp.getBuffer(); out.close(); } gp.flush(); } }; #endif // PLOTERRFUNC_H