diff --git a/lib/Plot.cpp b/lib/Plot.cpp index 023693a..bc031e2 100644 --- a/lib/Plot.cpp +++ b/lib/Plot.cpp @@ -129,6 +129,36 @@ PlotFunction::PlotFunction(const DoubleFunction &function, const double xMin, setCommand("'" + tmpFileName + "' u 1:2 w lines"); } +// PlotPredBand constructor //////////////////////////////////////////////////// +PlotPredBand::PlotPredBand(const DoubleFunctionSample &function, + const double xMin, const double xMax, + const unsigned int nPoint, const double opacity) +{ + DMat dLow(nPoint, 2), dHigh(nPoint, 2); + DSample pred(function.size()); + double dx = (xMax - xMin)/static_cast(nPoint - 1); + string lowFileName, highFileName; + + for (Index i = 0; i < nPoint; ++i) + { + double x = xMin + i*dx, err; + + pred = function(x); + err = sqrt(pred.variance()); + dLow(i, 0) = x; + dLow(i, 1) = pred[central] - err; + dHigh(i, 0) = x; + dHigh(i, 1) = pred[central] + err; + } + lowFileName = dumpToTmpFile(dLow); + highFileName = dumpToTmpFile(dHigh); + pushTmpFile(lowFileName); + pushTmpFile(highFileName); + setCommand("'< (cat " + lowFileName + "; tac " + highFileName + + "; head -n1 " + lowFileName + ")' u 1:2 w filledcurves closed" + + " fs solid " + strFrom(opacity) + " noborder"); +} + /****************************************************************************** * Plot modifiers * ******************************************************************************/ @@ -171,6 +201,17 @@ void PlotRange::operator()(PlotOptions &option) const option.scale[a].max = max_; } +// Title constructor /////////////////////////////////////////////////////////// +Terminal::Terminal(const string &terminal, const std::string &options) +: terminalCmd_(terminal + " " + options) +{} + +// Title modifier ////////////////////////////////////////////////////////////// +void Terminal::operator()(PlotOptions &option) const +{ + option.terminal = terminalCmd_; +} + // Title constructor /////////////////////////////////////////////////////////// Title::Title(const string &title) : title_(title) diff --git a/lib/Plot.hpp b/lib/Plot.hpp index 82618dd..75a16af 100644 --- a/lib/Plot.hpp +++ b/lib/Plot.hpp @@ -92,6 +92,17 @@ public: virtual ~PlotFunction(void) = default; }; +class PlotPredBand: public PlotObject +{ +public: + // constructor + PlotPredBand(const DoubleFunctionSample &function, const double xMin, + const double xMax, const unsigned int nPoint = 1000, + const double opacity = 0.15); + // destructor + virtual ~PlotPredBand(void) = default; +}; + /****************************************************************************** * Plot modifiers * ******************************************************************************/ @@ -162,6 +173,20 @@ private: const double min_, max_; }; +class Terminal: public PlotModifier +{ +public: + // constructor + Terminal(const std::string &terminal, const std::string &options = ""); + // destructor + virtual ~Terminal(void) = default; + // modifier + virtual void operator()(PlotOptions &option) const; +private: + const std::string terminalCmd_; +}; + + class Title: public PlotModifier { public: