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>
153 template <
class TVal1,
class TVal2>
157 template <
class TVal1,
class TVal2,
class TVal3>
161 template <
class TVal1,
class TVal2>
166 template <
class TKey,
class TVal,
class THashFunc>
170 template <
class TKey,
class TVal,
class THashFunc>
174 template <
class TKey,
class TVal,
class THashFunc>
177 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
179 template <
class TKey,
class TVal,
class THashFunc>
183 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
185 template <
class TVal1>
188 bool PlotAvg=
true,
bool PlotMed=
true,
bool PlotMin=
false,
bool PlotMax=
false,
bool PlotSDev=
false,
bool PlotStdErr=
true,
bool PlotScatter=
false);
189 template <
class TVal1>
191 const TStr& OutFNmPref,
const TStr& Desc=
"",
193 bool PlotAvg=
true,
bool PlotMed=
true,
bool PlotMin=
false,
bool PlotMax=
false,
bool PlotSDev=
false,
bool PlotStdErr=
true,
bool PlotScatter=
false);
194 template <
class TVal2>
197 template <
class TVal2>
225 template <
class TVal1,
class TVal2>
227 FILE *F = fopen(FNm.
CStr(),
"wt");
229 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
230 for (
int i = 0; i < ValV.Len(); i++) {
231 fprintf(F,
"%g\t%g\n",
double(ValV[i].Val1),
double(ValV[i].Val2)); }
235 template <
class TVal1,
class TVal2,
class TVal3>
237 FILE *F = fopen(FNm.
CStr(),
"wt");
239 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
240 for (
int i = 0; i < ValV.Len(); i++) {
241 fprintf(F,
"%g\t%g\t%g\n",
double(ValV[i].Val1),
double(ValV[i].Val2),
double(ValV[i].Val3)); }
245 template <
class TVal,
int Vals>
247 FILE *F = fopen(FNm.
CStr(),
"wt");
249 if (! HeadLn.
Empty()) { fprintf(F,
"# %s\n", HeadLn.
CStr()); }
250 for (
int i = 0; i < ValV.Len(); i++) {
251 fprintf(F,
"%g",
double(ValV[i][0]));
252 for (
int v = 1; v < Vals; v++) {
253 fprintf(F,
"\t%g",
double(ValV[i][v])); }
259 template<
class TKey,
class TDat,
class THashFunc>
269 BucketV.
Swap(XYFltValV);
271 return AddPlot(XYFltValV, SeriesTy, Label, Style);
274 template<
class TKey,
class THashFunc>
275 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) {
277 TFltPrV AvgV2, MedV, MinV, MaxV, BucketV;
279 TMom Mom(ValMomH[i]);
281 const double x = ValMomH.
GetKey(i);
285 else if (PlotStdErr) {
306 if (! AvgV.
Empty()) { PlotId =
AddErrBar(AvgV, Label+
" Average", Label+
" StdDev"); }
307 if (! AvgV2.
Empty()) { PlotId =
AddPlot(AvgV2, SeriesTy, Label+
" Average", Style); }
308 if (! MedV.
Empty()) { PlotId =
AddPlot(MedV, SeriesTy, Label+
" Median", Style); }
309 if (! MinV.
Empty()) { PlotId =
AddPlot(MinV, SeriesTy, Label+
" Min", Style); }
310 if (! MaxV.
Empty()) { PlotId =
AddPlot(MaxV, SeriesTy, Label+
" Max", Style); }
311 if (! StdErrV.
Empty()) { PlotId =
AddErrBar(StdErrV, Label+
" Average", Label+
" StdErr"); }
315 template <
class TVal1,
class TVal2>
319 for (
int i = 0; i < ValV.Len(); i++) {
320 IdCntV.
Add(
TFltKd(
double(ValV[i].Val1),
double(ValV[i].Val2))); }
321 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
326 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
329 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
330 if (MaxY < MinY) {
Swap(MaxY, MinY); }
337 template <
class TVal1,
class TVal2,
class TVal3>
339 const TStr& XLabel,
const TStr& YLabel,
const TGpScaleTy& ScaleTy,
const bool& PowerFit,
342 TFltV DeltaYV(ValV.Len(), 0);
343 for (
int i = 0; i < ValV.Len(); i++) {
344 IdCntV.
Add(
TFltKd(
double(ValV[i].Val1),
double(ValV[i].Val2)));
345 DeltaYV.
Add(
double(ValV[i].Val3));
347 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
352 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
353 GP.
AddErrBar(IdCntV, DeltaYV, ErrBarStr);
356 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
357 if (MaxY < MinY) {
Swap(MaxY, MinY); }
364 template <
class TVal1,
class TVal2>
367 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
369 TFltKdV IdCntV1(ValV1.Len(), 0), IdCntV2(ValV2.Len(), 0);
370 for (
int i = 0; i < ValV1.Len(); i++) {
371 IdCntV1.
Add(
TFltKd(
double(ValV1[i].Val1),
double(ValV1[i].Val2))); }
372 for (
int i = 0; i < ValV2.Len(); i++) {
373 IdCntV2.Add(
TFltKd(
double(ValV2[i].Val1),
double(ValV2[i].Val2))); }
374 if (IdCntV1.Empty() || IdCntV2.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
380 {
const int Id = GP.
AddPlot(IdCntV1, SeriesTy, Name1);
383 double MaxY = IdCntV1.Last().Dat, MinY = IdCntV1[0].Dat;
384 if (MaxY < MinY) {
Swap(MaxY, MinY); }
387 {
const int Id = GP.
AddPlot(IdCntV2, SeriesTy, Name2);
390 double MaxY = IdCntV2.Last().Dat, MinY = IdCntV2[0].Dat;
391 if (MaxY < MinY) {
Swap(MaxY, MinY); }
397 template <
class TVal1>
401 for (
int i = 0; i < ValV.
Len(); i++) {
402 IdCntV.
Add(
TFltKd(
double(i+1),
double(ValV[i]))); }
403 if (IdCntV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
408 const int Id = GP.
AddPlot(IdCntV, SeriesTy);
411 double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
412 if (MaxY < MinY) {
Swap(MaxY, MinY); }
419 template <
class TKey,
class TVal,
class THashFunc>
425 ValV.
Add(
double(ValCntH[i])); }
427 for (
int i = 0; i < ValV.Len(); i++) {
428 IdCntV.Add(
TFltPr(i+1, ValV[i]));
430 PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
433 template <
class TKey,
class TVal,
class THashFunc>
435 const TStr& XLabel,
const TStr& YLabel,
const TGpScaleTy& ScaleTy,
const bool& PowerFit,
436 const TGpSeriesTy& SeriesTy,
const bool& PlotCCDF,
const bool& ExpBucket) {
443 BucketV.Swap(IdCntV);
447 for (
int i = NCdfV.
Len()-2; i >= 0; i--) {
448 NCdfV[i].Val2 = NCdfV[i].Val2 + NCdfV[i+1].Val2;
450 PlotValV(NCdfV, OutFNmPref, Desc,
"NCDF "+XLabel,
"NCDF "+YLabel, ScaleTy, PowerFit, SeriesTy);
452 PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
456 template <
class TKey,
class TVal,
class THashFunc>
459 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
461 PlotValCntH(ValCntH1, Label1, ValCntH2, Label2,
THash<TKey, TVal, THashFunc>(),
"", OutFNmPref, Desc, XLabel, YLabel,
465 template <
class TKey,
class TVal,
class THashFunc>
469 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
const TStr& YLabel,
471 TFltPrV IdCntV1(ValCntH1.
Len(), 0), IdCntV2(ValCntH2.
Len(), 0), IdCntV3(ValCntH3.
Len(), 0);
473 IdCntV1.
Add(
TFltPr(
double(ValCntH1.
GetKey(i)),
double(ValCntH1[i]))); }
475 IdCntV2.Add(
TFltPr(
double(ValCntH2.
GetKey(i)),
double(ValCntH2[i]))); }
477 IdCntV3.Add(
TFltPr(
double(ValCntH3.
GetKey(i)),
double(ValCntH3[i]))); }
484 if (! IdCntV1.Empty()) { GP.
AddPlot(IdCntV1, SeriesTy, Label1); }
485 if (! IdCntV2.Empty()) { GP.
AddPlot(IdCntV2, SeriesTy, Label2); }
486 if (! IdCntV3.Empty()) { GP.
AddPlot(IdCntV3, SeriesTy, Label3); }
490 template <
class TVal1>
493 bool PlotAvg,
bool PlotMed,
bool PlotMin,
bool PlotMax,
bool PlotSDev,
bool PlotStdErr,
496 TFltPrV AvgV2, MedV, MinV, MaxV;
499 TMom Mom(ValMomH[i]);
501 const double x = ValMomH.
GetKey(i);
517 for (
int xi = 0; xi < ValMomH[i].GetVals(); xi++) {
518 PointSet.
AddKey(ValMomH[i].GetVal(xi)); }
520 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
532 if (! AvgV2.
Empty()) { GP.
AddPlot(AvgV2, SeriesTy,
"Average"); }
533 if (! MedV.
Empty()) { GP.
AddPlot(MedV, SeriesTy,
"Median"); }
534 if (! MinV.
Empty()) { GP.
AddPlot(MinV, SeriesTy,
"Min"); }
535 if (! MaxV.
Empty()) { GP.
AddPlot(MaxV, SeriesTy,
"Max"); }
536 if (! StdErrV.
Empty()) { GP.
AddErrBar(StdErrV,
"Standard error"); }
540 template <
class TVal1>
543 const TStr& OutFNmPref,
const TStr& Desc,
const TStr& XLabel,
545 bool PlotMed,
bool PlotMin,
bool PlotMax,
bool PlotSDev,
bool PlotStdErr,
bool PlotScatter) {
546 TFltTrV AvgV1, AvgV2, StdErrV1, StdErrV2;
547 TFltPrV AvgVM1, MedV1, MinV1, MaxV1;
548 TFltPrV AvgVM2, MedV2, MinV2, MaxV2;
552 TMom Mom(ValMomH1[i]);
554 const double x = ValMomH1.
GetKey(i);
570 for (
int xi = 0; xi < ValMomH1[i].GetVals(); xi++) {
571 PointSet.
AddKey(ValMomH1[i].GetVal(xi)); }
572 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
573 ScatterV1.
Add(
TFltPr(x, PointSet[xi])); }
579 TMom Mom(ValMomH2[i]);
581 const double x = ValMomH2.
GetKey(i);
597 for (
int xi = 0; xi < ValMomH2[i].GetVals(); xi++) {
598 PointSet.
AddKey(ValMomH2[i].GetVal(xi)); }
599 for (
int xi = 0; xi < PointSet.
Len(); xi++) {
600 ScatterV2.
Add(
TFltPr(x, PointSet[xi])); }
610 if (! AvgV1.
Empty()) { GP.
AddErrBar(AvgV1, Label1+
": Average", Label1+
": StdDev"); }
611 if (! AvgVM1.
Empty()) { GP.
AddPlot(AvgVM1, SeriesTy, Label1+
": Average"); }
612 if (! MedV1.
Empty()) { GP.
AddPlot(MedV1, SeriesTy, Label1+
": Median"); }
613 if (! MinV1.
Empty()) { GP.
AddPlot(MinV1, SeriesTy, Label1+
": Min"); }
614 if (! MaxV1.
Empty()) { GP.
AddPlot(MaxV1, SeriesTy, Label1+
": Max"); }
615 if (! StdErrV1.
Empty()) { GP.
AddErrBar(StdErrV1, Label1+
": Std error"); }
618 if (! AvgV2.
Empty()) { GP.
AddErrBar(AvgV2, Label2+
": Average", Label2+
": StdDev"); }
619 if (! AvgVM2.
Empty()) { GP.
AddPlot(AvgVM2, SeriesTy, Label2+
": Average"); }
620 if (! MedV2.
Empty()) { GP.
AddPlot(MedV2, SeriesTy, Label2+
": Median"); }
621 if (! MinV2.
Empty()) { GP.
AddPlot(MinV2, SeriesTy, Label2+
": Min"); }
622 if (! MaxV2.
Empty()) { GP.
AddPlot(MaxV2, SeriesTy, Label2+
": Max"); }
623 if (! StdErrV2.
Empty()) { GP.
AddErrBar(StdErrV2, Label2+
": Std error"); }
627 template <
class TVal2>
630 if (ValV.Empty()) { printf(
"*** Empty plot %s\n", OutFNmPref.
CStr());
return; }
636 GP.
AddCmd(
"set xdata time");
637 GP.
AddCmd(
"set timefmt \"%Y-%m-%d-%H:%M:%S\"");
638 GP.
AddCmd(
"set format x \"%Y-%m-%d\\n%H:%M:%S\"");
641 time_t ltime; time(<ime);
642 char* TimeStr = ctime(<ime); TimeStr[strlen(TimeStr) - 1] = 0;
645 fprintf(F,
"# %s (%s)\n", Desc.
CStr(), TimeStr);
647 fprintf(F,
"#Time\t%s\n", XLabel.
CStr());
648 for (
int i = 0; i < TmpV.
Len(); i++) {
649 fprintf(F,
"%s\t%g\n", TmpV[i].Val1.GetYmdTmStr2().CStr(), double(TmpV[i].Val2()));
657 template <
class TVal2>
662 PlotValOverTm(TmpV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, SeriesTy);
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)
static void PlotValOverTm(const TVec< TPair< TSecTm, TVal2 > > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
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())
static void PlotCntOverTm(const THash< TSecTm, TVal2 > &CntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
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.
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 TStr Fmt(const char *FmtStr,...)
static TStr GnuPlotPath
Path to GnuPlot executable. Set if gnuplot is not found in the PATH.
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const
static void PlotValRank(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)
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
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 &PlotCCDF=false, const bool &ExpBucket=false)
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)
static void PlotValV(const TVec< TVal1 > &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)
const TKey & GetKey(const int &KeyId) const
void Swap(TRec &Rec1, TRec &Rec2)