1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 08:55:37 +00:00

Plot: band plot and terminal option

This commit is contained in:
Antonin Portelli 2014-04-18 11:29:17 +01:00
parent dfe6240c14
commit 78372fb18a
2 changed files with 66 additions and 0 deletions

View File

@ -129,6 +129,36 @@ PlotFunction::PlotFunction(const DoubleFunction &function, const double xMin,
setCommand("'" + tmpFileName + "' u 1:2 w lines"); 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<double>(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 * * Plot modifiers *
******************************************************************************/ ******************************************************************************/
@ -171,6 +201,17 @@ void PlotRange::operator()(PlotOptions &option) const
option.scale[a].max = max_; 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 constructor ///////////////////////////////////////////////////////////
Title::Title(const string &title) Title::Title(const string &title)
: title_(title) : title_(title)

View File

@ -92,6 +92,17 @@ public:
virtual ~PlotFunction(void) = default; 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 * * Plot modifiers *
******************************************************************************/ ******************************************************************************/
@ -162,6 +173,20 @@ private:
const double min_, max_; 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 class Title: public PlotModifier
{ {
public: public: