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:
parent
dfe6240c14
commit
78372fb18a
41
lib/Plot.cpp
41
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<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 *
|
||||
******************************************************************************/
|
||||
@ -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)
|
||||
|
25
lib/Plot.hpp
25
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:
|
||||
|
Loading…
Reference in New Issue
Block a user