61 int IsSameXCol(
const int& CurId,
const int& PrevId)
const;
66 TGnuPlot(
const TStr& DataFileNm,
const TStr& PlotFileNm,
const TStr& PlotTitle,
const bool& Grid);
97 template<
class TKey,
class TDat,
class THashFunc>
99 template<
class TKey,
class THashFunc>
101 bool PlotAvg=
true,
bool PlotMed=
true,
bool PlotMin=
false,
bool PlotMax=
false,
bool PlotSDev=
false,
bool PlotStdErr=
false,
const bool& ExpBucket=
false);
116 int AddPwrFit3(
const int& PlotId,
const TGpSeriesTy& SeriesTy,
const double& MinX,
const TStr& Style,
double& Intercept,
double& Slope,
double& R2);
120 void SavePng(
const int& SizeX=1000,
const int& SizeY=800,
const TStr& Comment=
TStr()) {
122 void SavePng(
const TStr& FNm,
const int& SizeX=1000,
const int& SizeY=800,
const TStr& Comment=
TStr(),
const TStr& Terminal=
TStr());
129 const double& BinFactor = 2,
const double& MinYVal = 1);
131 const double& BinFactor = 2,
const double& MinYVal = 1);
140 template <
class TVal1,
class TVal2>
142 template <
class TVal1,
class TVal2,
class TVal3>
144 template <
class TVal,
int Vals>
149 template <
class TVal1,
class TVal2>
153 template <
class TVal1,
class TVal2,
class TVal3>
157 template <
class TVal1,
class TVal2>
162 template <
class TVal1>
166 template <
class TKey,
class TVal,
class THashFunc>
170 template <
class TKey,
class TVal,
class THashFunc>
173 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
175 template <
class TKey,
class TVal,
class THashFunc>
179 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
181 template <
class TVal1>
184 bool PlotAvg=
true,
bool PlotMed=
true,
bool PlotMin=
false,
bool PlotMax=
false,
bool PlotSDev=
false,
bool PlotStdErr=
true,
bool PlotScatter=
false);
185 template <
class TVal1>
187 const TStr& OutFNmPref,
const TStr& Desc=
"",
189 bool PlotAvg=
true,
bool PlotMed=
true,
bool PlotMin=
false,
bool PlotMax=
false,
bool PlotSDev=
false,
bool PlotStdErr=
true,
bool PlotScatter=
false);
214 template <
class TVal1,
class TVal2>
216 FILE *F = fopen(FNm.
CStr(),
"wt");
218 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
219 for (
int i = 0; i < ValV.Len(); i++) {
220 fprintf(F,
"%g\t%g\n",
double(ValV[i].Val1),
double(ValV[i].Val2)); }
224 template <
class TVal1,
class TVal2,
class TVal3>
226 FILE *F = fopen(FNm.
CStr(),
"wt");
228 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
229 for (
int i = 0; i < ValV.Len(); i++) {
230 fprintf(F,
"%g\t%g\t%g\n",
double(ValV[i].Val1),
double(ValV[i].Val2),
double(ValV[i].Val3)); }
234 template <
class TVal,
int Vals>
236 FILE *F = fopen(FNm.
CStr(),
"wt");
238 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
239 for (
int i = 0; i < ValV.Len(); i++) {
240 fprintf(F,
"%g",
double(ValV[i][0]));
241 for (
int v = 1; v < Vals; v++) {
242 fprintf(F,
"\t%g",
double(ValV[i][v])); }
248 template<
class TKey,
class TDat,
class THashFunc>
258 BucketV.
Swap(XYFltValV);
260 return AddPlot(XYFltValV, SeriesTy, Label, Style);
263 template<
class TKey,
class THashFunc>
264 int TGnuPlot::AddPlot(
const THash<TKey, TMom, THashFunc>& ValMomH,
const TGpSeriesTy& SeriesTy,
const TStr& Label,
const TStr& Style,
bool PlotAvg,
bool PlotMed,
bool PlotMin,
bool PlotMax,
bool PlotSDev,
bool PlotStdErr,
const bool& ExpBucket) {
266 TFltPrV AvgV2, MedV, MinV, MaxV, BucketV;
268 TMom Mom(ValMomH[i]);
270 const double x = ValMomH.
GetKey(i);
274 else if (PlotStdErr) {
295 if (! AvgV.
Empty()) { PlotId =
AddErrBar(AvgV, Label+
" Average", Label+
" StdDev"); }
296 if (! AvgV2.
Empty()) { PlotId =
AddPlot(AvgV2, SeriesTy, Label+
" Average", Style); }
297 if (! MedV.
Empty()) { PlotId =
AddPlot(MedV, SeriesTy, Label+
" Median", Style); }
298 if (! MinV.
Empty()) { PlotId =
AddPlot(MinV, SeriesTy, Label+
" Min", Style); }
299 if (! MaxV.
Empty()) { PlotId =
AddPlot(MaxV, SeriesTy, Label+
" Max", Style); }
300 if (! StdErrV.
Empty()) { PlotId =
AddErrBar(StdErrV, Label+
" Average", Label+
" StdErr"); }
305 template <
class TKey,
class TVal,
class THashFunc>
308 const bool& PlotNCDF,
const bool& ExpBucket) {
315 BucketV.Swap(IdCntV);
319 for (
int i = NCdfV.
Len()-2; i >= 0; i--) {
320 NCdfV[i].Val2 = NCdfV[i].Val2 + NCdfV[i+1].Val2;
322 PlotValV(NCdfV, OutFNmPref, Desc,
"NCDF "+XLabel,
"NCDF "+YLabel, ScaleTy, PowerFit, SeriesTy);
324 PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
328 template <
class TKey,
class TVal,
class THashFunc>
331 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
333 PlotValCntH(ValCntH1, Label1, ValCntH2, Label2,
THash<TKey, TVal, THashFunc>(),
"", OutFNmPref, Desc, XLabel, YLabel,
337 template <
class TKey,
class TVal,
class THashFunc>
341 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
343 TFltPrV IdCntV1(ValCntH1.
Len(), 0), IdCntV2(ValCntH2.
Len(), 0), IdCntV3(ValCntH3.
Len(), 0);
345 IdCntV1.
Add(
TFltPr(
double(ValCntH1.
GetKey(i)),
double(ValCntH1[i]))); }
347 IdCntV2.Add(
TFltPr(
double(ValCntH2.
GetKey(i)),
double(ValCntH2[i]))); }
349 IdCntV3.Add(
TFltPr(
double(ValCntH3.
GetKey(i)),
double(ValCntH3[i]))); }
356 if (! IdCntV1.Empty()) { GP.
AddPlot(IdCntV1, SeriesTy, Label1); }
357 if (! IdCntV2.Empty()) { GP.
AddPlot(IdCntV2, SeriesTy, Label2); }
358 if (! IdCntV3.Empty()) { GP.
AddPlot(IdCntV3, SeriesTy, Label3); }
362 template <
class TVal1,
class TVal2>
366 for (
int i = 0; i < ValV.Len(); i++) {
367 IdCntV.
Add(
TFltKd(
double(ValV[i].Val1),
double(ValV[i].Val2))); }
368 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
373 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
376 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
377 if (MaxY < MinY) {
Swap(MaxY, MinY); }
384 template <
class TVal1,
class TVal2,
class TVal3>
388 TFltV DeltaYV(ValV.Len(), 0);
389 for (
int i = 0; i < ValV.Len(); i++) {
390 IdCntV.
Add(
TFltKd(
double(ValV[i].Val1),
double(ValV[i].Val2)));
391 DeltaYV.
Add(
double(ValV[i].Val3));
393 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
398 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
399 GP.
AddErrBar(IdCntV, DeltaYV, ErrBarStr);
402 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
403 if (MaxY < MinY) {
Swap(MaxY, MinY); }
411 template <
class TVal1,
class TVal2>
415 TFltKdV IdCntV1(ValV1.Len(), 0), IdCntV2(ValV2.Len(), 0);
416 for (
int i = 0; i < ValV1.Len(); i++) {
417 IdCntV1.
Add(
TFltKd(
double(ValV1[i].Val1),
double(ValV1[i].Val2))); }
418 for (
int i = 0; i < ValV2.Len(); i++) {
419 IdCntV2.Add(
TFltKd(
double(ValV2[i].Val1),
double(ValV2[i].Val2))); }
420 if (IdCntV1.Empty() || IdCntV2.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
426 {
const int Id = GP.
AddPlot(IdCntV1, SeriesTy, Name1);
429 double MaxY = IdCntV1.Last().Dat, MinY = IdCntV1[0].Dat;
430 if (MaxY < MinY) {
Swap(MaxY, MinY); }
433 {
const int Id = GP.
AddPlot(IdCntV2, SeriesTy, Name2);
436 double MaxY = IdCntV2.Last().Dat, MinY = IdCntV2[0].Dat;
437 if (MaxY < MinY) {
Swap(MaxY, MinY); }
445 template <
class TVal1>
449 for (
int i = 0; i < ValV.
Len(); i++) {
450 IdCntV.
Add(
TFltKd(
double(i+1),
double(ValV[i]))); }
451 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
456 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
459 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
460 if (MaxY < MinY) {
Swap(MaxY, MinY); }
467 template <
class TVal1>
470 bool PlotAvg,
bool PlotMed,
bool PlotMin,
bool PlotMax,
bool PlotSDev,
bool PlotStdErr,
bool PlotScatter) {
472 TFltPrV AvgV2, MedV, MinV, MaxV;
475 TMom Mom(ValMomH[i]);
477 const double x = ValMomH.
GetKey(i);
493 for (
int xi = 0; xi < ValMomH[i].GetVals(); xi++) {
494 PointSet.
AddKey(ValMomH[i].GetVal(xi)); }
496 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
508 if (! AvgV2.
Empty()) { GP.
AddPlot(AvgV2, SeriesTy,
"Average"); }
509 if (! MedV.
Empty()) { GP.
AddPlot(MedV, SeriesTy,
"Median"); }
510 if (! MinV.
Empty()) { GP.
AddPlot(MinV, SeriesTy,
"Min"); }
511 if (! MaxV.
Empty()) { GP.
AddPlot(MaxV, SeriesTy,
"Max"); }
512 if (! StdErrV.
Empty()) { GP.
AddErrBar(StdErrV,
"Standard error"); }
516 template <
class TVal1>
519 bool PlotAvg,
bool PlotMed,
bool PlotMin,
bool PlotMax,
bool PlotSDev,
bool PlotStdErr,
bool PlotScatter) {
520 TFltTrV AvgV1, AvgV2, StdErrV1, StdErrV2;
521 TFltPrV AvgVM1, MedV1, MinV1, MaxV1;
522 TFltPrV AvgVM2, MedV2, MinV2, MaxV2;
526 TMom Mom(ValMomH1[i]);
528 const double x = ValMomH1.
GetKey(i);
544 for (
int xi = 0; xi < ValMomH1[i].GetVals(); xi++) {
545 PointSet.
AddKey(ValMomH1[i].GetVal(xi)); }
546 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
547 ScatterV1.
Add(
TFltPr(x, PointSet[xi])); }
553 TMom Mom(ValMomH2[i]);
555 const double x = ValMomH2.
GetKey(i);
571 for (
int xi = 0; xi < ValMomH2[i].GetVals(); xi++) {
572 PointSet.
AddKey(ValMomH2[i].GetVal(xi)); }
573 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
574 ScatterV2.
Add(
TFltPr(x, PointSet[xi])); }
584 if (! AvgV1.
Empty()) { GP.
AddErrBar(AvgV1, Label1+
": Average", Label1+
": StdDev"); }
585 if (! AvgVM1.
Empty()) { GP.
AddPlot(AvgVM1, SeriesTy, Label1+
": Average"); }
586 if (! MedV1.
Empty()) { GP.
AddPlot(MedV1, SeriesTy, Label1+
": Median"); }
587 if (! MinV1.
Empty()) { GP.
AddPlot(MinV1, SeriesTy, Label1+
": Min"); }
588 if (! MaxV1.
Empty()) { GP.
AddPlot(MaxV1, SeriesTy, Label1+
": Max"); }
589 if (! StdErrV1.
Empty()) { GP.
AddErrBar(StdErrV1, Label1+
": Std error"); }
592 if (! AvgV2.
Empty()) { GP.
AddErrBar(AvgV2, Label2+
": Average", Label2+
": StdDev"); }
593 if (! AvgVM2.
Empty()) { GP.
AddPlot(AvgVM2, SeriesTy, Label2+
": Average"); }
594 if (! MedV2.
Empty()) { GP.
AddPlot(MedV2, SeriesTy, Label2+
": Median"); }
595 if (! MinV2.
Empty()) { GP.
AddPlot(MinV2, SeriesTy, Label2+
": Min"); }
596 if (! MaxV2.
Empty()) { GP.
AddPlot(MaxV2, SeriesTy, Label2+
": Max"); }
597 if (! StdErrV2.
Empty()) { GP.
AddErrBar(StdErrV2, Label2+
": Std error"); }
TGnuPlot & operator=(const TGnuPlot &GnuPlot)
int AddLinFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
int AddExpFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &FitXOffset=0.0, const TStr &Style=TStr())
void SetLineStyle(const int &PlotId, const TStr &StyleStr)
bool operator<(const TGpSeries &Gps) const
void SetXRange(const double &Min, const double &Max)
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
void SavePng(const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr())
TGnuPlot(const TStr &FileNm="gplot", const TStr &PlotTitle=TStr(), const bool &Grid=true)
void SetTitle(const TStr &PlotTitle)
void SetYLabel(const TStr &YLabel)
TGpSeriesCmp(const TVec< TGpSeries > &_SeriesV)
TSizeTy Len() const
Returns the number of elements in the vector.
bool operator()(const int &Left, const int &Right) const
void SetXYLabel(const TStr &XLabel, const TStr &YLabel)
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
TKeyDat< TFlt, TFlt > TFltKd
void SetDataPlotFNm(const TStr &DatFNm, const TStr &PltFNm)
TGpSeries & operator=(const TGpSeries &Gps)
void Plot(const TStr &Comment=TStr())
TVec< TGpSeries > SeriesV
void SetYRange(const double &Min, const double &Max)
int AddPwrFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
bool Empty() const
Tests whether the vector is empty.
static void LoadTs(const TStr &FNm, TStrV &ColNmV, TVec< TFltKdV > &ColV)
static void PlotValMomH(const THash< TVal1, TMom > &ValMomH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints, bool PlotAvg=true, bool PlotMed=true, bool PlotMin=false, bool PlotMax=false, bool PlotSDev=false, bool PlotStdErr=true, bool PlotScatter=false)
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
static void SaveTs(const TIntKdV &KdV, const TStr &FNm, const TStr &HeadLn=TStr())
void AddCmd(const TStr &Cmd)
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
static void PlotValCntH(const THash< TKey, TVal, THashFunc > &ValCntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const bool &PlotNCDF=false, const bool &ExpBucket=false)
TStr GetLineStyle(const int &PlotId) const
static TStr GetSeriesTyStr(const TGpSeriesTy &SeriesTy)
const TVec< TGpSeries > & SeriesV
bool FNextKeyId(int &KeyId) const
int AddLogFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
void Pause(const bool &DoPause)
int AddKey(const TKey &Key)
TTriple< TFlt, TFlt, TFlt > TFltTr
TPair< TFlt, TFlt > TFltPr
void SaveEps(const int &FontSz=30, const TStr &Comment=TStr())
int AddPwrFit2(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
int IsSameXCol(const int &CurId, const int &PrevId) const
void SetScale(const TGpScaleTy &GpScaleTy)
static void PlotValV(const TVec< TPair< TVal1, TVal2 > > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
static TStr Fmt(const char *FmtStr,...)
static TStr GnuPlotPath
Path to GnuPlot executable. Set if gnuplot is not found in the PATH.
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
void ShowGrid(const bool &Show)
static TStr GetScaleStr(const TGpScaleTy &ScaleTy)
int AddPwrFit1(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
TStr GetSeriesPlotStr(const int &PlotN)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
static TStr GnuPlotFNm
GnuPlot executable file name. Set if different than the standard wgnuplot/gnuplot.
void CreatePlotFile(const TStr &Comment=TStr())
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
void SetXLabel(const TStr &XLabel)
const TKey & GetKey(const int &KeyId) const
void Swap(TRec &Rec1, TRec &Rec2)