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

Absolute value plot (useful for log scale)

This commit is contained in:
Antonin Portelli 2021-12-14 13:13:36 +00:00
parent b92fb84e9d
commit c796187d1e
2 changed files with 54 additions and 15 deletions

View File

@ -112,7 +112,7 @@ PlotHeadCommand::PlotHeadCommand(const string &command)
}
// PlotData constructor ////////////////////////////////////////////////////////
PlotData::PlotData(const DMatSample &x, const DMatSample &y)
PlotData::PlotData(const DMatSample &x, const DMatSample &y, const bool abs)
{
if (x[central].rows() != y[central].rows())
{
@ -128,10 +128,17 @@ PlotData::PlotData(const DMatSample &x, const DMatSample &y)
d.col(3) = y.variance().cwiseSqrt();
tmpFileName = dumpToTmpFile(d);
pushTmpFile(tmpFileName);
setCommand("'" + tmpFileName + "' u 1:3:2:4 w xyerr");
if (!abs)
{
setCommand("'" + tmpFileName + "' u 1:3:2:4 w xyerr");
}
else
{
setCommand("'" + tmpFileName + "' u 1:(abs($3)):2:4 w xyerr");
}
}
PlotData::PlotData(const DVec &x, const DMatSample &y)
PlotData::PlotData(const DVec &x, const DMatSample &y, const bool abs)
{
if (x.rows() != y[central].rows())
{
@ -146,10 +153,17 @@ PlotData::PlotData(const DVec &x, const DMatSample &y)
d.col(2) = y.variance().cwiseSqrt();
tmpFileName = dumpToTmpFile(d);
pushTmpFile(tmpFileName);
setCommand("'" + tmpFileName + "' u 1:2:3 w yerr");
if (!abs)
{
setCommand("'" + tmpFileName + "' u 1:2:3 w yerr");
}
else
{
setCommand("'" + tmpFileName + "' u 1:(abs($2)):3 w yerr");
}
}
PlotData::PlotData(const DMatSample &x, const DVec &y)
PlotData::PlotData(const DMatSample &x, const DVec &y, const bool abs)
{
if (x[central].rows() != y.rows())
{
@ -164,14 +178,29 @@ PlotData::PlotData(const DMatSample &x, const DVec &y)
d.col(1) = x.variance().cwiseSqrt();
tmpFileName = dumpToTmpFile(d);
pushTmpFile(tmpFileName);
setCommand("'" + tmpFileName + "' u 1:3:2 w xerr");
if (!abs)
{
setCommand("'" + tmpFileName + "' u 1:3:2 w xerr");
}
else
{
setCommand("'" + tmpFileName + "' u 1:($3):2 w xerr");
}
}
PlotData::PlotData(const XYStatData &data, const Index i, const Index j)
PlotData::PlotData(const XYStatData &data, const Index i, const Index j, const bool abs)
{
string usingCmd, tmpFileName;
usingCmd = (data.isXExact(i)) ? "u 1:3:4 w yerr" : "u 1:3:2:4 w xyerr";
if (!abs)
{
usingCmd = (data.isXExact(i)) ? "u 1:3:4 w yerr" : "u 1:3:2:4 w xyerr";
}
else
{
usingCmd = (data.isXExact(i)) ? "u 1:(abs($3)):4 w yerr" : "u 1:(abs($3)):2:4 w xyerr";
}
tmpFileName = dumpToTmpFile(data.getTable(i, j));
pushTmpFile(tmpFileName);
setCommand("'" + tmpFileName + "' " + usingCmd);
@ -217,7 +246,8 @@ PlotBand::PlotBand(const double xMin, const double xMax, const double yMin,
// PlotFunction constructor ////////////////////////////////////////////////////
PlotFunction::PlotFunction(const DoubleFunction &function, const double xMin,
const double xMax, const unsigned int nPoint)
const double xMax, const unsigned int nPoint,
const bool abs)
{
DMat d(nPoint, 2);
string tmpFileName;
@ -230,7 +260,14 @@ PlotFunction::PlotFunction(const DoubleFunction &function, const double xMin,
}
tmpFileName = dumpToTmpFile(d);
pushTmpFile(tmpFileName);
setCommand("'" + tmpFileName + "' u 1:2 w lines");
if (!abs)
{
setCommand("'" + tmpFileName + "' u 1:2 w lines");
}
else
{
setCommand("'" + tmpFileName + "' u 1:(abs($2)) w lines");
}
}
// PlotPredBand constructor ////////////////////////////////////////////////////

View File

@ -89,10 +89,11 @@ class PlotData: public PlotObject
{
public:
// constructor
PlotData(const DMatSample &x, const DMatSample &y);
PlotData(const DVec &x, const DMatSample &y);
PlotData(const DMatSample &x, const DVec &y);
PlotData(const XYStatData &data, const Index i = 0, const Index j = 0);
PlotData(const DMatSample &x, const DMatSample &y, const bool abs = false);
PlotData(const DVec &x, const DMatSample &y, const bool abs = false);
PlotData(const DMatSample &x, const DVec &y, const bool abs = false);
PlotData(const XYStatData &data, const Index i = 0, const Index j = 0,
const bool abs = false);
// destructor
virtual ~PlotData(void) = default;
};
@ -130,7 +131,8 @@ class PlotFunction: public PlotObject
public:
// constructor
PlotFunction(const DoubleFunction &function, const double xMin,
const double xMax, const unsigned int nPoint = 1000);
const double xMax, const unsigned int nPoint = 1000,
const bool abs = false);
// destructor
virtual ~PlotFunction(void) = default;
};