SNAP Library 3.0, User Reference  2016-07-20 17:56:49
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
TGnuPlot Class Reference

#include <gnuplot.h>

Classes

class  TGpSeries
 
class  TGpSeriesCmp
 

Public Member Functions

TStr GetSeriesPlotStr (const int &PlotN)
 
int IsSameXCol (const int &CurId, const int &PrevId) const
 
void CreatePlotFile (const TStr &Comment=TStr())
 
void RunGnuPlot () const
 
 TGnuPlot (const TStr &FileNm="gplot", const TStr &PlotTitle=TStr(), const bool &Grid=true)
 
 TGnuPlot (const TStr &DataFileNm, const TStr &PlotFileNm, const TStr &PlotTitle, const bool &Grid)
 
 TGnuPlot (const TGnuPlot &GnuPlot)
 
TGnuPlotoperator= (const TGnuPlot &GnuPlot)
 
void SetTitle (const TStr &PlotTitle)
 
void SetXLabel (const TStr &XLabel)
 
void SetYLabel (const TStr &YLabel)
 
void SetXYLabel (const TStr &XLabel, const TStr &YLabel)
 
void SetDataPlotFNm (const TStr &DatFNm, const TStr &PltFNm)
 
void ShowGrid (const bool &Show)
 
void Pause (const bool &DoPause)
 
void SetScale (const TGpScaleTy &GpScaleTy)
 
void SetXRange (const double &Min, const double &Max)
 
void SetYRange (const double &Min, const double &Max)
 
void AddCmd (const TStr &Cmd)
 
TStr GetLineStyle (const int &PlotId) const
 
void SetLineStyle (const int &PlotId, const TStr &StyleStr)
 
int AddFunc (const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TFltV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TFltV &XValV, const TFltV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TIntPrV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TFltPrV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TIntKdV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TFltKdV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TIntFltKdV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TIntFltPrV &XYValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TStr &DataFNm, const int &ColY, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
int AddPlot (const TStr &DataFNm, const int &ColX, const int &ColY, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
 
template<class TKey , class TDat , class THashFunc >
int AddPlot (const THash< TKey, TDat, THashFunc > &XYValH, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr(), const bool &ExpBucket=false)
 
template<class TKey , class THashFunc >
int AddPlot (const THash< TKey, TMom, THashFunc > &ValMomH, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr(), bool PlotAvg=true, bool PlotMed=true, bool PlotMin=false, bool PlotMax=false, bool PlotSDev=false, bool PlotStdErr=false, const bool &ExpBucket=false)
 
int AddErrBar (const TFltTrV &XYDValV, const TStr &Label=TStr())
 
int AddErrBar (const TFltTrV &XYDValV, const TStr &DatLabel, const TStr &ErrLabel)
 
int AddErrBar (const TFltV &YValV, const TFltV &DeltaYV, const TStr &Label=TStr())
 
int AddErrBar (const TFltV &XValV, const TFltV &YValV, const TFltV &DeltaYV, const TStr &Label=TStr())
 
int AddErrBar (const TFltPrV &XYValV, const TFltV &DeltaYV, const TStr &Label=TStr())
 
int AddErrBar (const TFltKdV &XYValV, const TFltV &DeltaYV, const TStr &Label=TStr())
 
int AddErrBar (const TFltPrV &XYValV, const TFltV &DeltaYV, const TStr &DatLabel, const TStr &ErrLabel)
 
int AddLinFit (const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
 
int AddPwrFit (const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
 
int AddPwrFit1 (const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
 
int AddPwrFit2 (const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
 
int AddPwrFit3 (const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
 
int AddPwrFit3 (const int &PlotId, const TGpSeriesTy &SeriesTy, const double &MinX, const TStr &Style, double &Intercept, double &Slope, double &R2)
 
int AddLogFit (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 SavePng (const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr())
 
void SavePng (const TStr &FNm, const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr(), const TStr &Terminal=TStr())
 
void SaveEps (const int &FontSz=30, const TStr &Comment=TStr())
 
void SaveEps (const TStr &FNm, const int &FontSz=30, const TStr &Comment=TStr())
 
void Plot (const TStr &Comment=TStr())
 

Static Public Member Functions

static int GetTics42 ()
 
static void MakeExpBins (const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
 
static void MakeExpBins (const TFltKdV &XYValV, TFltKdV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
 
static void LoadTs (const TStr &FNm, TStrV &ColNmV, TVec< TFltKdV > &ColV)
 
static TStr GetScaleStr (const TGpScaleTy &ScaleTy)
 
static TStr GetSeriesTyStr (const TGpSeriesTy &SeriesTy)
 
static void SaveTs (const TIntKdV &KdV, const TStr &FNm, const TStr &HeadLn=TStr())
 
static void SaveTs (const TIntFltKdV &KdV, const TStr &FNm, const TStr &HeadLn=TStr())
 
template<class TVal1 , class TVal2 >
static void SaveTs (const TVec< TPair< TVal1, TVal2 > > &ValV, const TStr &FNm, const TStr &HeadLn=TStr())
 
template<class TVal1 , class TVal2 , class TVal3 >
static void SaveTs (const TVec< TTriple< TVal1, TVal2, TVal3 > > &ValV, const TStr &FNm, const TStr &HeadLn=TStr())
 
template<class TVal , int Vals>
static void SaveTs (const TVec< TTuple< TVal, Vals > > &ValV, const TStr &FNm, const TStr &HeadLn=TStr())
 
static void Test ()
 
template<class TVal1 >
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)
 
template<class TVal1 , class TVal2 >
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)
 
template<class TVal1 , class TVal2 , class TVal3 >
static void PlotValV (const TVec< TTriple< TVal1, TVal2, TVal3 > > &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 TStr &ErrBarStr="")
 
template<class TVal1 , class TVal2 >
static void PlotValV (const TVec< TPair< TVal1, TVal2 > > &ValV1, const TStr &Name1, const TVec< TPair< TVal1, TVal2 > > &ValV2, const TStr &Name2, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
 
template<class TKey , class TVal , class THashFunc >
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)
 
template<class TKey , class TVal , class THashFunc >
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)
 
template<class TKey , class TVal , class THashFunc >
static void PlotValCntH (const THash< TKey, TVal, THashFunc > &ValCntH1, const TStr &Label1, const THash< TKey, TVal, THashFunc > &ValCntH2, const TStr &Label2, const TStr &OutFNmPref, const TStr &Desc, const TStr &XLabel, const TStr &YLabel, const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
 
template<class TKey , class TVal , class THashFunc >
static void PlotValCntH (const THash< TKey, TVal, THashFunc > &ValCntH1, const TStr &Label1, const THash< TKey, TVal, THashFunc > &ValCntH2, const TStr &Label2, const THash< TKey, TVal, THashFunc > &ValCntH3, const TStr &Label3, const TStr &OutFNmPref, const TStr &Desc, const TStr &XLabel, const TStr &YLabel, const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
 
template<class TVal1 >
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)
 
template<class TVal1 >
static void PlotValMomH (const THash< TVal1, TMom > &ValMomH1, const TStr &Label1, const THash< TVal1, TMom > &ValMomH2, const TStr &Label2, 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)
 
template<class TVal2 >
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)
 
template<class TVal2 >
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)
 

Static Public Attributes

static TStr GnuPlotPath = "/usr/bin"
 Path to GnuPlot executable. Set if gnuplot is not found in the PATH. More...
 
static TStr GnuPlotFNm = "gnuplot"
 GnuPlot executable file name. Set if different than the standard wgnuplot/gnuplot. More...
 
static TStr DefPlotFNm = "GnuPlot.plt"
 
static TStr DefDataFNm = "GnuPlot.tab"
 

Private Attributes

TStr DataFNm
 
TStr PlotFNm
 
TStr Title
 
TStr LblX
 
TStr LblY
 
TGpScaleTy ScaleTy
 
TFltPr YRange
 
TFltPr XRange
 
bool SetGrid
 
bool SetPause
 
TVec< TGpSeriesSeriesV
 
TStrV MoreCmds
 

Static Private Attributes

static int Tics42 = -2
 

Detailed Description

Definition at line 16 of file gnuplot.h.

Constructor & Destructor Documentation

TGnuPlot::TGnuPlot ( const TStr FileNm = "gplot",
const TStr PlotTitle = TStr(),
const bool &  Grid = true 
)

Definition at line 86 of file gnuplot.cpp.

86  :
87  DataFNm(FileNm+".tab"), PlotFNm(FileNm+".plt"), Title(PlotTitle), LblX(), LblY(), ScaleTy(gpsAuto),
88  YRange(0, 0), XRange(0, 0), SetGrid(Grid), SetPause(true),
89  SeriesV(), MoreCmds() {
90  IAssert(! FileNm.Empty());
91 }
#define IAssert(Cond)
Definition: bd.h:262
TFltPr XRange
Definition: gnuplot.h:53
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
Definition: gnuplot.h:7
bool SetPause
Definition: gnuplot.h:54
bool SetGrid
Definition: gnuplot.h:54
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TStr LblX
Definition: gnuplot.h:51
bool Empty() const
Definition: dt.h:488
TFltPr YRange
Definition: gnuplot.h:53
TStr PlotFNm
Definition: gnuplot.h:50
TStrV MoreCmds
Definition: gnuplot.h:56
TGnuPlot::TGnuPlot ( const TStr DataFileNm,
const TStr PlotFileNm,
const TStr PlotTitle,
const bool &  Grid 
)

Definition at line 93 of file gnuplot.cpp.

93  :
94  DataFNm(DataFileNm.Empty() ? DefDataFNm : DataFileNm),
95  PlotFNm(PlotFileNm.Empty() ? DefPlotFNm : PlotFileNm),
96  Title(PlotTitle), LblX(), LblY(), ScaleTy(gpsAuto),
97  YRange(0, 0), XRange(0, 0), SetGrid(Grid), SetPause(true), SeriesV(), MoreCmds() {
98 }
TFltPr XRange
Definition: gnuplot.h:53
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
Definition: gnuplot.h:7
bool SetPause
Definition: gnuplot.h:54
bool SetGrid
Definition: gnuplot.h:54
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TStr LblX
Definition: gnuplot.h:51
bool Empty() const
Definition: dt.h:488
static TStr DefDataFNm
Definition: gnuplot.h:23
TFltPr YRange
Definition: gnuplot.h:53
static TStr DefPlotFNm
Definition: gnuplot.h:22
TStr PlotFNm
Definition: gnuplot.h:50
TStrV MoreCmds
Definition: gnuplot.h:56
TGnuPlot::TGnuPlot ( const TGnuPlot GnuPlot)

Definition at line 100 of file gnuplot.cpp.

100  : DataFNm(GnuPlot.DataFNm), PlotFNm(GnuPlot.PlotFNm),
101  Title(GnuPlot.Title), LblX(GnuPlot.LblX), LblY(GnuPlot.LblY), ScaleTy(GnuPlot.ScaleTy), YRange(GnuPlot.YRange),
102  XRange(GnuPlot.XRange), SetGrid(GnuPlot.SetGrid), SetPause(GnuPlot.SetPause), SeriesV(GnuPlot.SeriesV),
103  MoreCmds(GnuPlot.MoreCmds) {
104 }
TFltPr XRange
Definition: gnuplot.h:53
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
bool SetPause
Definition: gnuplot.h:54
bool SetGrid
Definition: gnuplot.h:54
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TStr LblX
Definition: gnuplot.h:51
TFltPr YRange
Definition: gnuplot.h:53
TStr PlotFNm
Definition: gnuplot.h:50
TStrV MoreCmds
Definition: gnuplot.h:56

Member Function Documentation

void TGnuPlot::AddCmd ( const TStr Cmd)
inline

Definition at line 81 of file gnuplot.h.

81 { MoreCmds.Add(Cmd); }
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TStrV MoreCmds
Definition: gnuplot.h:56
int TGnuPlot::AddErrBar ( const TFltTrV XYDValV,
const TStr Label = TStr() 
)

Definition at line 265 of file gnuplot.cpp.

265  {
266  TFltKdV XYFltValV(XYDValV.Len(), 0);
267  TFltV DeltaV(XYDValV.Len(), 0);
268  for (int i = 0; i < XYDValV.Len(); i++) {
269  XYFltValV.Add(TFltKd(XYDValV[i].Val1, XYDValV[i].Val2));
270  DeltaV.Add(XYDValV[i].Val3);
271  }
272  return AddErrBar(XYFltValV, DeltaV, Label);
273 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddErrBar ( const TFltTrV XYDValV,
const TStr DatLabel,
const TStr ErrLabel 
)

Definition at line 275 of file gnuplot.cpp.

275  {
276  TFltKdV XYFltValV(XYDValV.Len(), 0);
277  TFltV DeltaV(XYDValV.Len(), 0);
278  for (int i = 0; i < XYDValV.Len(); i++) {
279  XYFltValV.Add(TFltKd(XYDValV[i].Val1, XYDValV[i].Val2));
280  DeltaV.Add(XYDValV[i].Val3);
281  }
282  const int PlotId = AddPlot(XYFltValV, gpwLinesPoints, DatLabel);
283  AddErrBar(XYFltValV, DeltaV, ErrLabel);
284  return PlotId;
285 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddErrBar ( const TFltV YValV,
const TFltV DeltaYV,
const TStr Label = TStr() 
)

Definition at line 287 of file gnuplot.cpp.

287  {
288  IAssert(YValV.Len() == DeltaYV.Len());
289  TFltKdV XYFltValV(YValV.Len(), 0);
290  for (int i = 0; i < YValV.Len(); i++) {
291  XYFltValV.Add(TFltKd(TFlt(i+1), YValV[i]));
292  }
293  return AddErrBar(XYFltValV, DeltaYV, Label);
294 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddErrBar ( const TFltV XValV,
const TFltV YValV,
const TFltV DeltaYV,
const TStr Label = TStr() 
)

Definition at line 296 of file gnuplot.cpp.

296  {
297  IAssert(XValV.Len() == YValV.Len());
298  IAssert(XValV.Len() == DeltaYV.Len());
299  TFltKdV XYFltValV(XValV.Len(), 0);
300  for (int i = 0; i < XValV.Len(); i++) {
301  XYFltValV.Add(TFltKd(XValV[i], YValV[i]));
302  }
303  return AddErrBar(XYFltValV, DeltaYV, Label);
304 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddErrBar ( const TFltPrV XYValV,
const TFltV DeltaYV,
const TStr Label = TStr() 
)

Definition at line 306 of file gnuplot.cpp.

306  {
307  TFltKdV XYFltValV(XYValV.Len(), 0);
308  for (int i = 0; i < XYValV.Len(); i++) {
309  XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
310  }
311  return AddErrBar(XYFltValV, DeltaYV, Label);
312 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddErrBar ( const TFltKdV XYValV,
const TFltV DeltaYV,
const TStr Label = TStr() 
)

Definition at line 324 of file gnuplot.cpp.

324  {
325  if (XYValV.Empty()) {
326  printf("***AddErrBar: empty plot (%s) %s\n", DataFNm.CStr(), Title.CStr());
327  return -1;
328  }
329  IAssert(XYValV.Len() == DeltaYV.Len());
330  TGpSeries Plot;
331  Plot.SeriesTy = gpwErrBars;
332  Plot.Label = Label;
333  Plot.XYValV = XYValV;
334  Plot.ZValV = DeltaYV;
335  SeriesV.Add(Plot);
336  return SeriesV.Len() - 1;
337 }
#define IAssert(Cond)
Definition: bd.h:262
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
char * CStr()
Definition: dt.h:476
int TGnuPlot::AddErrBar ( const TFltPrV XYValV,
const TFltV DeltaYV,
const TStr DatLabel,
const TStr ErrLabel 
)

Definition at line 314 of file gnuplot.cpp.

314  {
315  TFltKdV XYFltValV(XYValV.Len(), 0);
316  for (int i = 0; i < XYValV.Len(); i++) {
317  XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
318  }
319  const int PlotId = AddPlot(XYFltValV, gpwLinesPoints, DatLabel);
320  AddErrBar(XYFltValV, DeltaV, ErrLabel);
321  return PlotId;
322 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddExpFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const double &  FitXOffset = 0.0,
const TStr Style = TStr() 
)

!! skip zero values

Definition at line 550 of file gnuplot.cpp.

550  {
551  const TGpSeries& Plot = SeriesV[PlotId];
552  if(Plot.XYValV.Empty()) return -1;
553  const TFltKdV& XY = Plot.XYValV;
554  double A, B, R2, SigA, SigB, Chi2;
555  // power fit
556  TFltPrV XYPr;
557  int s;
558  for (s = 0; s < XY.Len(); s++) {
559  if (XY[s].Key-FitXOffset > 0) {
560  XYPr.Add(TFltPr(XY[s].Key-FitXOffset, XY[s].Dat)); }
561  }
562  TSpecFunc::ExpFit(XYPr, A, B, SigA, SigB, Chi2, R2);
563  TStr Label, StyleStr=Style;
564  if (FitXOffset == 0) { Label = TStr::Fmt("%.4g exp(%.4g x) R^2:%.2g", A, B, R2); }
565  else { Label = TStr::Fmt("%.4g exp(%.4g x - %g) R^2:%.2g", A, B, FitXOffset, R2); }
566  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
567  const int FitId = AddFunc(TStr::Fmt("%f*exp(%f*x-%f)", A, B, FitXOffset),
568  SeriesTy, Label, StyleStr);
569  return FitId;
570  /*SeriesV.Add();
571  TGpSeries& NewPlot = SeriesV.Last();
572  TFltKdV& EstXY = NewPlot.XYValV;
573  for (s = 0; s < XYPr.Len(); s++) {
574  EstXY.Add(TFltKd(XYPr[s].Val1+FitXOffset, A*exp(B*XYPr[s].Val1)));
575  }
576  NewPlot.SeriesTy = SeriesTy;
577  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
578  else { NewPlot.WithStyle = Style; }
579  return SeriesV.Len() - 1;*/
580 }
static void ExpFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:218
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
int TGnuPlot::AddFunc ( const TStr FuncStr,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 155 of file gnuplot.cpp.

155  {
156  const int Id = SeriesV.Len();
157  TGpSeries Plot;
158  Plot.SeriesTy = SeriesTy;
159  Plot.Label = Label;
160  if (! FuncStr.Empty()) { Plot.DataFNm = TStr::Fmt("f%d(x)=%s, f%d(x)", Id, FuncStr.CStr(), Id); }
161  else { Plot.DataFNm = TStr::Fmt("f%d(x)", Id); }
162  Plot.XCol = -1;
163  Plot.WithStyle = Style;
164  SeriesV.Add(Plot);
165  return Id;
166 }
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
int TGnuPlot::AddLinFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

Definition at line 339 of file gnuplot.cpp.

339  {
340  if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1;
341  const TGpSeries& Plot = SeriesV[PlotId];
342  if(Plot.XYValV.Empty()) return -1;
343  const TFltKdV& XY = Plot.XYValV;
344  double A, B, R2, SigA, SigB, Chi2;
345  // linear fit
346  TFltPrV XYPr;
347  int s;
348  for (s = 0; s < XY.Len(); s++) {
349  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
350  }
351  TSpecFunc::LinearFit(XYPr, A, B, SigA, SigB, Chi2, R2);
352  TStr StyleStr=Style;
353  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
354  const int FitId = AddFunc(TStr::Fmt("%f+%f*x", A, B),
355  SeriesTy, TStr::Fmt("%.4g + %.4g x R^2:%.2g", A, B, R2), StyleStr);
356  return FitId;
357  /*SeriesV.Add();
358  TGpSeries& NewPlot = SeriesV.Last();
359  TFltKdV& EstXY = NewPlot.XYValV;
360  for (s = 0; s < XY.Len(); s++) {
361  EstXY.Add(TFltKd(XY[s].Key, A + B*XYPr[s].Val1));
362  }
363  NewPlot.Label = TStr::Fmt("%.4g + %.4g x R^2:%.2g", A, B, R2);
364  NewPlot.SeriesTy = SeriesTy;
365  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
366  else { NewPlot.WithStyle = Style; }
367  return SeriesV.Len() - 1;*/
368 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static void LinearFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:150
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
int TGnuPlot::AddLogFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

!! skip zero values

Definition at line 519 of file gnuplot.cpp.

519  {
520  const TGpSeries& Plot = SeriesV[PlotId];
521  if(Plot.XYValV.Empty()) return -1;
522  const TFltKdV& XY = Plot.XYValV;
523  double A, B, R2, SigA, SigB, Chi2;
524  // power fit
525  TFltPrV XYPr;
526  int s;
527  for (s = 0; s < XY.Len(); s++) {
528  if (XY[s].Key > 0) {
529  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat)); }
530  }
531  TSpecFunc::LogFit(XYPr, A, B, SigA, SigB, Chi2, R2);
532  TStr StyleStr=Style;
533  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
534  const int FitId = AddFunc(TStr::Fmt("%f+%f*log(x)", A, B),
535  SeriesTy, TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2), StyleStr);
536  return FitId;
537  /*SeriesV.Add();
538  TGpSeries& NewPlot = SeriesV.Last();
539  TFltKdV& EstXY = NewPlot.XYValV;
540  for (s = 0; s < XYPr.Len(); s++) {
541  EstXY.Add(TFltKd(XYPr[s].Val1, A+B*log((double)XYPr[s].Val1)));
542  }
543  NewPlot.Label = TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2);
544  NewPlot.SeriesTy = SeriesTy;
545  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
546  else { NewPlot.WithStyle = Style; }
547  return SeriesV.Len() - 1;*/
548 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static void LogFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:208
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
int TGnuPlot::AddPlot ( const TIntV YValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 186 of file gnuplot.cpp.

186  {
187  TFltKdV XYValV(YValV.Len(), 0);
188  for (int i = 0; i < YValV.Len(); i++) {
189  XYValV.Add(TFltKd(TFlt(i+1), TFlt(YValV[i])));
190  }
191  return AddPlot(XYValV, SeriesTy, Label, Style);
192 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TFltV YValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 194 of file gnuplot.cpp.

194  {
195  TFltKdV XYValV(YValV.Len(), 0);
196  for (int i = 0; i < YValV.Len(); i++) {
197  XYValV.Add(TFltKd(TFlt(i+1), TFlt(YValV[i])));
198  }
199  return AddPlot(XYValV, SeriesTy, Label, Style);
200 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TFltV XValV,
const TFltV YValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 202 of file gnuplot.cpp.

202  {
203  IAssert(XValV.Len() == YValV.Len());
204  TFltKdV XYValV(XValV.Len(), 0);
205  for (int i = 0; i < YValV.Len(); i++) {
206  XYValV.Add(TFltKd(TFlt(XValV[i]), TFlt(YValV[i])));
207  }
208  return AddPlot(XYValV, SeriesTy, Label, Style);
209 }
#define IAssert(Cond)
Definition: bd.h:262
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TIntPrV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 211 of file gnuplot.cpp.

211  {
212  TFltKdV XYFltValV(XYValV.Len(), 0);
213  for (int i = 0; i < XYValV.Len(); i++) {
214  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Val1), TFlt(XYValV[i].Val2)));
215  }
216  return AddPlot(XYFltValV, SeriesTy, Label, Style);
217 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TFltPrV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 219 of file gnuplot.cpp.

219  {
220  TFltKdV XYFltValV(XYValV.Len(), 0);
221  for (int i = 0; i < XYValV.Len(); i++) {
222  XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
223  }
224  return AddPlot(XYFltValV, SeriesTy, Label, Style);
225 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TIntKdV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 227 of file gnuplot.cpp.

227  {
228  TFltKdV XYFltValV(XYValV.Len(), 0);
229  for (int i = 0; i < XYValV.Len(); i++) {
230  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Key), TFlt(XYValV[i].Dat)));
231  }
232  return AddPlot(XYFltValV, SeriesTy, Label, Style);
233 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TFltKdV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 251 of file gnuplot.cpp.

251  {
252  if (XYValV.Empty()) {
253  printf("***AddPlot: empty plot (%s) %s\n", DataFNm.CStr(), Title.CStr());
254  return -1;
255  }
256  TGpSeries Plot;
257  Plot.SeriesTy = SeriesTy;
258  Plot.Label = Label;
259  Plot.XYValV = XYValV;
260  Plot.WithStyle = Style;
261  SeriesV.Add(Plot);
262  return SeriesV.Len() - 1;
263 }
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
char * CStr()
Definition: dt.h:476
int TGnuPlot::AddPlot ( const TIntFltKdV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 235 of file gnuplot.cpp.

235  {
236  TFltKdV XYFltValV(XYValV.Len(), 0);
237  for (int i = 0; i < XYValV.Len(); i++) {
238  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Key), TFlt(XYValV[i].Dat)));
239  }
240  return AddPlot(XYFltValV, SeriesTy, Label, Style);
241 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TIntFltPrV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 243 of file gnuplot.cpp.

243  {
244  TFltKdV XYFltValV(XYValV.Len(), 0);
245  for (int i = 0; i < XYValV.Len(); i++) {
246  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Val1), TFlt(XYValV[i].Val2)));
247  }
248  return AddPlot(XYFltValV, SeriesTy, Label, Style);
249 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int TGnuPlot::AddPlot ( const TStr DataFNm,
const int &  ColY,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 168 of file gnuplot.cpp.

169  {
170  return AddPlot(DataFNm, 0, ColY, SeriesTy, Label, Style);
171 }
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
int TGnuPlot::AddPlot ( const TStr DataFNm,
const int &  ColX,
const int &  ColY,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 173 of file gnuplot.cpp.

174  {
175  IAssert(ColY > 0); IAssert(ColX >= 0);
176  TGpSeries Plot;
177  Plot.SeriesTy = SeriesTy;
178  Plot.Label = Label;
179  Plot.DataFNm = DataFNm; Plot.DataFNm.ChangeStrAll("\\", "\\\\");
180  Plot.XCol = ColX; Plot.YCol = ColY; Plot.ZCol = 0;
181  Plot.WithStyle = Style;
182  SeriesV.Add(Plot);
183  return SeriesV.Len() - 1;
184 }
#define IAssert(Cond)
Definition: bd.h:262
TStr DataFNm
Definition: gnuplot.h:50
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
template<class TKey , class TDat , class THashFunc >
int TGnuPlot::AddPlot ( const THash< TKey, TDat, THashFunc > &  XYValH,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr(),
const bool &  ExpBucket = false 
)

Definition at line 260 of file gnuplot.h.

260  {
261  TFltPrV XYFltValV(XYValH.Len(), 0);
262  for (int k = XYValH.FFirstKeyId(); XYValH.FNextKeyId(k); ) {
263  XYFltValV.Add(TFltPr(TFlt(XYValH.GetKey(k)), TFlt(XYValH[k])));
264  }
265  XYFltValV.Sort();
266  if (ExpBucket) {
267  TFltPrV BucketV;
268  TGnuPlot::MakeExpBins(XYFltValV, BucketV);
269  BucketV.Swap(XYFltValV);
270  }
271  return AddPlot(XYFltValV, SeriesTy, Label, Style);
272 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:614
Definition: dt.h:1293
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1047
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int Len() const
Definition: hash.h:186
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TKey , class THashFunc >
int TGnuPlot::AddPlot ( const THash< TKey, TMom, THashFunc > &  ValMomH,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr(),
bool  PlotAvg = true,
bool  PlotMed = true,
bool  PlotMin = false,
bool  PlotMax = false,
bool  PlotSDev = false,
bool  PlotStdErr = false,
const bool &  ExpBucket = false 
)

Definition at line 275 of file gnuplot.h.

275  {
276  TFltTrV AvgV, StdErrV;
277  TFltPrV AvgV2, MedV, MinV, MaxV, BucketV;
278  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
279  TMom Mom(ValMomH[i]);
280  if (! Mom.IsDef()) { Mom.Def(); }
281  const double x = ValMomH.GetKey(i);
282  if (PlotAvg) {
283  if (PlotSDev) {
284  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
285  else if (PlotStdErr) {
286  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
287  } else {
288  AvgV2.Add(TFltPr(x, Mom.GetMean()));
289  }
290  }
291  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
292  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
293  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
294  }
295  AvgV.Sort(); AvgV2.Sort();
296  MedV.Sort(); MinV.Sort(); MaxV.Sort();
297  int PlotId=0;
298  // exponential bucketing
299  if (ExpBucket) {
300  if (! AvgV2.Empty()) { TGnuPlot::MakeExpBins(AvgV2, BucketV); BucketV.Swap(AvgV2); }
301  if (! MedV.Empty()) { TGnuPlot::MakeExpBins(MedV, BucketV); BucketV.Swap(MedV); }
302  if (! MinV.Empty()) { TGnuPlot::MakeExpBins(MinV, BucketV); BucketV.Swap(MinV); }
303  if (! MaxV.Empty()) { TGnuPlot::MakeExpBins(MaxV, BucketV); BucketV.Swap(MaxV); }
304  }
305  // plot
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"); }
312  return PlotId;
313 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:614
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1047
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1254
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:180
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
int TGnuPlot::AddPwrFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

Definition at line 370 of file gnuplot.cpp.

370  {
371  const int PlotId1 = AddPwrFit3(PlotId, SeriesTy);
372  AddPwrFit2(PlotId, SeriesTy, 5.0);
373  return PlotId1;
374 }
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:467
int AddPwrFit2(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:419
int TGnuPlot::AddPwrFit1 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

!! skip zero values

Definition at line 377 of file gnuplot.cpp.

377  {
378  if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1;
379  const TGpSeries& Plot = SeriesV[PlotId];
380  if(Plot.XYValV.Empty()) return -1;
381  const TFltKdV& XY = Plot.XYValV;
382  double A, B, R2, SigA, SigB, Chi2, MinY = TFlt::Mx, MinX = TFlt::Mx;
383  // power fit
384  TFltPrV XYPr;
385  int s;
386  for (s = 0; s < XY.Len(); s++) {
387  if (XY[s].Key > 0) {
388  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
389  MinX = TMath::Mn(MinX, XY[s].Key());
390  MinY = TMath::Mn(MinY, XY[s].Dat());
391  }
392  }
393  MinY = TMath::Mn(1.0, MinY);
394  TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2);
395  TStr StyleStr=Style;
396  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
397  const int FitId = AddFunc(TStr::Fmt("%f*x**%f", A, B),
398  SeriesTy, TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2), StyleStr);
399  return FitId;
400  /*SeriesV.Add();
401  TGpSeries& NewPlot = SeriesV.Last();
402  const int FitId = SeriesV.Len() - 1;
403  NewPlot.DataFNm = ;
404  TFltKdV& EstXY = NewPlot.XYValV;
405  for (s = 0; s < XYPr.Len(); s++) {
406  const double YVal = A*pow(XYPr[s].Val1(), B);
407  if (YVal < MinY) continue;
408  EstXY.Add(TFltKd(XYPr[s].Val1, YVal));
409  }
410  NewPlot.Label = ;
411  NewPlot.SeriesTy = SeriesTy;
412  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
413  else { NewPlot.WithStyle = Style; }
414  //if (MinX < 5.0) MinX = 5.0;
415  //AddPwrFit2(PlotId, SeriesTy, MinX);*/
416 }
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:193
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static const double Mx
Definition: dt.h:1298
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
int TGnuPlot::AddPwrFit2 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const double &  MinX = -1.0,
const TStr Style = TStr() 
)

Definition at line 419 of file gnuplot.cpp.

419  {
420  const TGpSeries& Plot = SeriesV[PlotId];
421  if(Plot.XYValV.Empty()) return -1;
422  const TFltKdV& XY = Plot.XYValV;
423  // power fit
424  TFltPrV XYPr;
425  double MinY = TFlt::Mx;
426  for (int s = 0; s < XY.Len(); s++) {
427  if (XY[s].Key > 0.0) {
428  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
429  MinY = TMath::Mn(MinY, XY[s].Dat());
430  }
431  }
432  if (XYPr.Empty()) return -1;
433  MinY = TMath::Mn(1.0, MinY);
434  // determine the sign of power coefficient
435  double CoefSign = 0.0;
436  { double A, B, R2, SigA, SigB, Chi2;
437  TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2);
438  CoefSign = B > 0.0 ? +1.0 : -1.0; }
439  const double PowerCf = CoefSign * TSpecFunc::GetPowerCoef(XYPr, MinX);
440  int Mid = (int) exp(log((double)XYPr.Len())/2.0);
441  if (Mid >= XYPr.Len()) { Mid = XYPr.Len()-1; }
442  const double MidX = XYPr[Mid].Val1();
443  const double MidY = XYPr[Mid].Val2();
444  const double B = MidY / pow(MidX, PowerCf);
445  TStr StyleStr=Style;
446  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
447  const int FitId = AddFunc(TStr::Fmt("%f*x**%f", B, PowerCf),
448  SeriesTy, TStr::Fmt("MLE = x^{%.4g}", PowerCf), StyleStr);
449  return FitId;
450  /*SeriesV.Add();
451  TGpSeries& NewPlot = SeriesV.Last();
452  TFltKdV& XYFit = NewPlot.XYValV;
453  XYFit.Gen(XYPr.Len(), 0);
454  for (int s = 0; s < XYPr.Len(); s++) {
455  const double XVal = XYPr[s].Val1;
456  const double YVal = B * pow(XYPr[s].Val1(), PowerCf);
457  if (YVal < MinY || XVal < MinX) continue;
458  XYFit.Add(TFltKd(XVal, YVal));
459  }
460  NewPlot.Label = TStr::Fmt("PowerFit: %g", PowerCf);
461  NewPlot.SeriesTy = SeriesTy;
462  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
463  else { NewPlot.WithStyle = Style; }
464  return SeriesV.Len() - 1;*/
465 }
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:193
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static const double Mx
Definition: dt.h:1298
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
static double GetPowerCoef(const TFltV &XValV, double MinX=-1.0)
Definition: xmath.cpp:299
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
int TGnuPlot::AddPwrFit3 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const double &  MinX = -1.0,
const TStr Style = TStr() 
)

Definition at line 467 of file gnuplot.cpp.

467  {
468  double Intercept, Slope, R2;
469  return AddPwrFit3(PlotId, SeriesTy, MinX, Style, Intercept, Slope, R2);
470 }
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:467
int TGnuPlot::AddPwrFit3 ( const int &  PlotId,
const TGpSeriesTy SeriesTy,
const double &  MinX,
const TStr Style,
double &  Intercept,
double &  Slope,
double &  R2 
)

!! skip zero values

Definition at line 473 of file gnuplot.cpp.

473  {
474  if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1;
475  const TGpSeries& Plot = SeriesV[PlotId];
476  if(Plot.XYValV.Empty()) return -1;
477  double A, B, SigA, SigB, Chi2, MinY=TFlt::Mx;
478  const TFltKdV& XY = Plot.XYValV;
479  //SeriesV.Add();
480  //TGpSeries& NewPlot = SeriesV.Last();
481  //TFltKdV& EstXY = NewPlot.XYValV;
482  TFltPrV FitXY, NewFitXY;
483  for (int s = 0; s < XY.Len(); s++) {
484  if (XY[s].Key > 0 && XY[s].Key >= MinX) {
485  FitXY.Add(TFltPr(XY[s].Key, XY[s].Dat));
486  MinY = TMath::Mn(MinY, XY[s].Dat());
487  }
488  }
489  MinY = TMath::Mn(1.0, MinY);
490  // power fit (if tail is too fat, cut everything where
491  // extrapolation sets the value < MinY
492  while (true) {
493  TSpecFunc::PowerFit(FitXY, A, B, SigA, SigB, Chi2, R2);
494  NewFitXY.Clr(false);
495  //EstXY.Clr(false);
496  for (int s = 0; s < FitXY.Len(); s++) {
497  const double YVal = A*pow(FitXY[s].Val1(), B);
498  if (YVal < MinY) continue;
499  //EstXY.Add(TFltKd(FitXY[s].Val1, YVal));
500  NewFitXY.Add(TFltPr(FitXY[s].Val1, FitXY[s].Val2));
501  }
502  if (NewFitXY.Len() < 10 || FitXY.Last().Val1 < 1.2 * NewFitXY.Last().Val1) { break; }
503  else { FitXY.Swap(NewFitXY); }
504  }
505  TStr StyleStr=Style;
506  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
507  const int FitId = AddFunc(TStr::Fmt("%f*x**%f", A, B),
508  SeriesTy, TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2), StyleStr);
509  return FitId;
510  /*NewPlot.Label = TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2);
511  Intercept = A;
512  Slope = B;
513  NewPlot.SeriesTy = SeriesTy;
514  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
515  else { NewPlot.WithStyle = Style; }
516  return SeriesV.Len() - 1;*/
517 }
static const T & Mn(const T &LVal, const T &RVal)
Definition: xmath.h:36
static void PowerFit(const TVec< TFltPr > &XY, double &A, double &B, double &SigA, double &SigB, double &Chi2, double &R2)
Definition: xmath.cpp:193
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static const double Mx
Definition: dt.h:1298
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1047
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:551
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
void TGnuPlot::CreatePlotFile ( const TStr Comment = TStr())

Definition at line 768 of file gnuplot.cpp.

768  {
769  time_t ltime; time(&ltime);
770  char* TimeStr = ctime(&ltime); TimeStr[strlen(TimeStr) - 1] = 0;
771  // rearrange columns so that longest are on the left
772  //SeriesV.Sort(false);
773  TIntV SerIdV(SeriesV.Len(), 0);
774  for (int i = 0; i < SeriesV.Len(); i++) { SerIdV.Add(i); }
775  SerIdV.SortCmp(TGpSeriesCmp(SeriesV));
776  // set columns
777  int ColCnt = 1;
778  bool SaveData = false;
779  for (int s = 0; s < SeriesV.Len(); s++) {
780  TGpSeries& Plt = SeriesV[SerIdV[s]];
781  if (Plt.XYValV.Empty()) { continue; }
782  Plt.DataFNm = DataFNm;
783  // plots use same X column
784  const int PrevCol = s > 0 ? IsSameXCol(SerIdV[s], SerIdV[s-1]) : -1;
785  if (PrevCol != -1) { Plt.XCol = PrevCol; }
786  else { Plt.XCol = ColCnt; ColCnt++; }
787  Plt.YCol = ColCnt; ColCnt++;
788  if (! Plt.ZValV.Empty()) { Plt.ZCol = ColCnt; ColCnt++; }
789  if (! Plt.XYValV.Empty()) { SaveData=true; }
790  }
791  // save data file (skip duplicate X columns)
792  if (SaveData) {
793  FILE *F = fopen(DataFNm.CStr(), "wt");
794  EAssertR(F != NULL, TStr("Can not open data file ")+DataFNm);
795  fprintf(F, "#\n");
796  fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
797  fprintf(F, "#\n");
798  // column names
799  for (int i = 0; i < SerIdV.Len(); i++) {
800  const TGpSeries& Ser = SeriesV[SerIdV[i]];
801  if (Ser.XYValV.Empty()) { continue; }
802  if (i == 0) { fprintf(F, "# "); } else { fprintf(F, "\t"); }
803  if (Ser.SaveXVals()) {
804  if (! LblX.Empty()) { fprintf(F, "%s\t", LblX.CStr()); }
805  else { fprintf(F, "XVals\t"); }
806  }
807  if (Ser.Label.Empty()) { fprintf(F, "%s", LblY.CStr()); }
808  else { fprintf(F, "%s", SeriesV[SerIdV[i]].Label.CStr()); }
809  if (Ser.ZCol > 0) fprintf(F, "\tDeltaY");
810  }
811  fprintf(F, "\n");
812  // data
813  for (int row = 0; row < SeriesV[SerIdV[0]].XYValV.Len(); row++) {
814  for (int i = 0; i < SeriesV.Len(); i++) {
815  const TGpSeries& Ser = SeriesV[SerIdV[i]];
816  if (row < Ser.XYValV.Len()) {
817  if (i > 0) { fprintf(F, "\t"); }
818  if (Ser.SaveXVals()) { fprintf(F, "%g\t%g", Ser.XYValV[row].Key(), Ser.XYValV[row].Dat()); }
819  else { fprintf(F, "%g", Ser.XYValV[row].Dat()); }
820  if (! Ser.ZValV.Empty()) { fprintf(F, "\t%g", Ser.ZValV[row]()); }
821  }
822  }
823  fprintf(F, "\n");
824  }
825  fclose(F);
826  }
827  // save plot file
828  FILE *F = fopen(PlotFNm.CStr(), "wt");
829  EAssertR(F != 0, TStr("Can not open plot file ")+PlotFNm);
830  TStr CurDir = TDir::GetCurDir();
831  CurDir.ChangeStrAll("\\", "\\\\");
832  fprintf(F, "#\n");
833  fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
834  fprintf(F, "#\n\n");
835  if (! Title.Empty()) fprintf(F, "set title \"%s\"\n", Title.CStr());
836  fprintf(F, "set key bottom right\n");
837  fprintf(F, "%s\n", GetScaleStr(ScaleTy).CStr());
839  fprintf(F, "set format x \"10^{%%L}\"\n");
840  fprintf(F, "set mxtics 10\n"); }
842  fprintf(F, "set format y \"10^{%%L}\"\n");
843  fprintf(F, "set mytics 10\n"); }
844  if (ScaleTy==gpsLog2X || ScaleTy==gpsLog2XY) { fprintf(F, "set format x \"2^{%%L}\"\n"); }
845  if (ScaleTy==gpsLog2Y || ScaleTy==gpsLog2XY) { fprintf(F, "set format y \"2^{%%L}\"\n"); }
846  if (SetGrid) fprintf(F, "set grid\n");
847  if (XRange.Val1 != XRange.Val2) fprintf(F, "set xrange [%g:%g]\n", XRange.Val1(), XRange.Val2());
848  if (YRange.Val1 != YRange.Val2) fprintf(F, "set yrange [%g:%g]\n", YRange.Val1(), YRange.Val2());
849  if (! LblX.Empty()) fprintf(F, "set xlabel \"%s\"\n", LblX.CStr());
850  if (! LblY.Empty()) fprintf(F, "set ylabel \"%s\"\n", LblY.CStr());
851  if (Tics42 < -1) {
852  Tics42 = GetTics42();
853  }
854  if (Tics42) {
855  fprintf(F, "set tics scale 2\n"); // New in version 4.2
856  } else {
857  fprintf(F, "set ticscale 2 1\n"); // Old (deprecated)
858  }
859  // custom commands
860  for (int i = 0; i < MoreCmds.Len(); i++) {
861  fprintf(F, "%s\n", MoreCmds[i].CStr()); }
862  // plot
863  if (! SeriesV.Empty()) {
864  fprintf(F, "plot \t");
865  for (int i = 0; i < SeriesV.Len(); i++) {
866  fprintf(F, "%s", GetSeriesPlotStr(i).CStr()); }
867  fprintf(F, "\n");
868  }
869  if (SetPause) fprintf(F, "pause -1 \"Hit return to exit. %s\"\n", PlotFNm.CStr());
870  fclose(F);
871 }
static TStr GetCurDir()
Definition: xfl.cpp:233
TFltPr XRange
Definition: gnuplot.h:53
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
static int GetTics42()
Definition: gnuplot.cpp:26
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
int ChangeStrAll(const TStr &SrcStr, const TStr &DstStr, const bool &FromStartP=false)
Definition: dt.cpp:1141
Definition: gnuplot.h:7
bool SetPause
Definition: gnuplot.h:54
bool SetGrid
Definition: gnuplot.h:54
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TStr LblX
Definition: gnuplot.h:51
int IsSameXCol(const int &CurId, const int &PrevId) const
Definition: gnuplot.cpp:758
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
TFltPr YRange
Definition: gnuplot.h:53
TVal1 Val1
Definition: ds.h:34
TVal2 Val2
Definition: ds.h:35
static TStr GetScaleStr(const TGpScaleTy &ScaleTy)
Definition: gnuplot.cpp:683
char * CStr()
Definition: dt.h:476
TStr GetSeriesPlotStr(const int &PlotN)
Definition: gnuplot.cpp:124
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TStr PlotFNm
Definition: gnuplot.h:50
static int Tics42
Definition: gnuplot.h:48
TStrV MoreCmds
Definition: gnuplot.h:56
TStr TGnuPlot::GetLineStyle ( const int &  PlotId) const
inline

Definition at line 82 of file gnuplot.h.

82 { return SeriesV[PlotId].WithStyle; }
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
TStr TGnuPlot::GetScaleStr ( const TGpScaleTy ScaleTy)
static

Definition at line 683 of file gnuplot.cpp.

683  {
684  switch(ScaleTy){
685  case gpsNoAuto: return TStr("set noautoscale");
686  case gpsAuto: return TStr("set autoscale");
687  case gpsLog: return TStr("set logscale");
688  case gpsLog2X: return TStr("set logscale x 2");
689  case gpsLog2Y: return TStr("set logscale y 2");
690  case gpsLog2XY: return TStr("set logscale xy 2");
691  case gpsLog10X: return TStr("set logscale x 10");
692  case gpsLog10Y: return TStr("set logscale y 10");
693  case gpsLog10XY: return TStr("set logscale xy 10");
694  default: Fail;
695  }
696  return TStr();
697 }
#define Fail
Definition: bd.h:238
Definition: gnuplot.h:7
Definition: gnuplot.h:7
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
Definition: dt.h:412
TStr TGnuPlot::GetSeriesPlotStr ( const int &  PlotN)

Definition at line 124 of file gnuplot.cpp.

124  {
125  TChA PlotStr;
126  TGpSeries& Series = SeriesV[SeriesId];
127  if (SeriesId != 0) PlotStr += ",\\\n\t";
128  if (Series.XCol >= 0) {
129  PlotStr += "\"" + Series.DataFNm + "\" using " + TInt::GetStr(Series.XCol);
130  if (Series.YCol != 0) { PlotStr += ":" + TInt::GetStr(Series.YCol); }
131  if (Series.ZCol != 0) { PlotStr += ":" + TInt::GetStr(Series.ZCol); }
132  else if (Series.SeriesTy==gpwFilledCurves) { PlotStr += ":(0)"; } // filled curves requres 3rd column
133  } else {
134  // function
135  //IAssertR(Series.DataFNm.SearchCh('=') != -1, TStr::Fmt("Expression %s is not a function", Series.DataFNm.CStr()));
136  PlotStr += Series.DataFNm;
137  }
138  if (Series.SeriesTy == gpwErrBars) {
139  PlotStr += " notitle";
140  } else {
141  PlotStr += " title \"" + Series.Label + "\"";
142  }
143  // hard coded line style
144  if (Series.WithStyle.Empty()) {
145  if (Series.SeriesTy == gpwLines) Series.WithStyle = "lw 1";
146  if (Series.SeriesTy == gpwPoints) Series.WithStyle = "pt 6"; // circles
147  if (Series.SeriesTy == gpwLinesPoints) Series.WithStyle = "pt 6"; // circles
148  if (Series.SeriesTy == gpwBoxes) Series.WithStyle = "fill solid 0.3";
149  }
150  PlotStr += " with " + GetSeriesTyStr(Series.SeriesTy) + " " + Series.WithStyle;
151  return PlotStr;
152 }
TStr GetStr() const
Definition: dt.h:1107
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static TStr GetSeriesTyStr(const TGpSeriesTy &SeriesTy)
Definition: gnuplot.cpp:699
Definition: dt.h:201
TStr TGnuPlot::GetSeriesTyStr ( const TGpSeriesTy SeriesTy)
static

Definition at line 699 of file gnuplot.cpp.

699  {
700  switch(SeriesTy) {
701  case gpwLines: return TStr("lines");
702  case gpwPoints: return TStr("points");
703  case gpwLinesPoints: return TStr("linespoints");
704  case gpwImpulses: return TStr("impulses");
705  case gpwDots: return TStr("dots");
706  case gpwSteps: return TStr("steps");
707  case gpwFSteps: return TStr("fsteps");
708  case gpwHiSteps: return TStr("histeps");
709  case gpwBoxes: return TStr("boxes");
710  case gpwErrBars: return TStr("errorbars");
711  case gpwFilledCurves: return TStr("filledcurves");
712  default: Fail;
713  }
714  return TStr();
715 }
#define Fail
Definition: bd.h:238
Definition: dt.h:412
int TGnuPlot::GetTics42 ( )
static

Definition at line 26 of file gnuplot.cpp.

26  {
27 #ifdef GLib_WIN
28  return -1;
29 #else
30  FILE* p;
31  char Buf[1024];
32  char Version[1024];
33  size_t n;
34 
35  // get gnuplot version
36  p = popen(TStr::Fmt("%s -V", TGnuPlot::GnuPlotFNm.CStr()).CStr(), "r");
37  if (p == NULL) { // try running using the path
38  p = popen(TStr::Fmt("%s/%s -V", TGnuPlot::GnuPlotPath.CStr(), TGnuPlot::GnuPlotFNm.CStr()).CStr(), "r");
39  if (p == NULL) { return -1; }
40  }
41  n = fread(Buf, 1, 100, p);
42  if (n <= 0) { return -1; }
43  Buf[n] = '\0';
44  pclose(p);
45  //printf("Buf %d .%s.\n", n, Buf);
46  n = sscanf(Buf, "gnuplot %s", Version);
47  if (n <= 0) { return -1; }
48  // printf("Version %d .%s.\n", n, Version);
49  if ((strlen(Version) < 3) || (Version[1] != '.')) { return -1; }
50  // test version < 4.2
51  if ((Version[0] < '4') || ((Version[0] == '4') && (Version[2] < '2'))) {
52  // printf("TGnuPlot::GetTics42 0\n");
53  return 0;
54  }
55  // printf("TGnuPlot::GetTics42 1\n");
56  return 1;
57 #endif
58 }
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static TStr GnuPlotPath
Path to GnuPlot executable. Set if gnuplot is not found in the PATH.
Definition: gnuplot.h:19
static TStr GnuPlotFNm
GnuPlot executable file name. Set if different than the standard wgnuplot/gnuplot.
Definition: gnuplot.h:21
int TGnuPlot::IsSameXCol ( const int &  CurId,
const int &  PrevId 
) const

Definition at line 758 of file gnuplot.cpp.

758  {
759  //if (SerId < 1) { return -1; }
760  if (SeriesV[CurId].XYValV.Len() != SeriesV[PrevId].XYValV.Len()) { return -1; }
761  for (int x = 0; x < SeriesV[CurId].XYValV.Len(); x++) {
762  if (SeriesV[CurId].XYValV[x] != SeriesV[PrevId].XYValV[x]) { return -1; }
763  }
764  IAssert(SeriesV[PrevId].XCol > 0);
765  return SeriesV[PrevId].XCol;
766 }
#define IAssert(Cond)
Definition: bd.h:262
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
void TGnuPlot::LoadTs ( const TStr FNm,
TStrV ColNmV,
TVec< TFltKdV > &  ColV 
)
static

Definition at line 665 of file gnuplot.cpp.

665  {
666  PSs Ss = TSs::LoadTxt(ssfTabSep, FNm);
667  int row = 0;
668  ColNmV.Clr();
669  while (Ss->At(0, row)[0] == '#') { row++; }
670  for (int c = 1; c < Ss->GetXLen(row); c+=2) {
671  ColNmV.Add(Ss->At(c, row));
672  }
673  row++;
674  ColV.Gen(ColNmV.Len(), ColNmV.Len());
675  for (; row < Ss->GetYLen(); row++) {
676  for (int c = 0; c < Ss->GetXLen(row); c+=2) {
677  if (Ss->At(c,row).Empty()) break;
678  ColV[c/2].Add(TFltKd(Ss->At(c,row).GetFlt(), Ss->At(c+1,row).GetFlt()));
679  }
680  }
681 }
static PSs LoadTxt(const TSsFmt &SsFmt, const TStr &FNm, const PNotify &Notify=NULL, const bool &IsExcelEoln=true, const int &MxY=-1, const TIntV &AllowedColNV=TIntV(), const bool &IsQStr=true)
Definition: ss.cpp:100
bool Empty() const
Definition: bd.h:501
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
Tab separated.
Definition: ss.h:6
Definition: bd.h:196
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void TGnuPlot::MakeExpBins ( const TFltPrV XYValV,
TFltPrV ExpXYValV,
const double &  BinFactor = 2,
const double &  MinYVal = 1 
)
static

Definition at line 614 of file gnuplot.cpp.

614  {
615  TFltKdV KdV(XYValV.Len(), 0), OutV;
616  for (int i = 0; i < XYValV.Len(); i++) {
617  KdV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2)); }
618  KdV.Sort();
619  TGnuPlot::MakeExpBins(KdV, OutV, BinFactor, MinYVal);
620  ExpXYValV.Gen(OutV.Len(), 0);
621  for (int i = 0; i < OutV.Len(); i++) {
622  ExpXYValV.Add(TFltPr(OutV[i].Key, OutV[i].Dat)); }
623 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:614
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void TGnuPlot::MakeExpBins ( const TFltKdV XYValV,
TFltKdV ExpXYValV,
const double &  BinFactor = 2,
const double &  MinYVal = 1 
)
static

Definition at line 625 of file gnuplot.cpp.

625  {
626  if (XYValV.Empty()) { ExpXYValV.Clr(false); return; }
627  IAssert(! XYValV.Empty());
628  IAssert(XYValV.IsSorted());
629  const TFlt MxX = XYValV.Last().Key;
630  // find buckets
631  TFltV BucketEndV; BucketEndV.Add(1);
632  double PrevBPos = 1, BPos = 1;
633  while (BPos <= MxX) {
634  PrevBPos = (uint) floor(BPos);
635  BPos *= BinFactor;
636  if (floor(BPos) == PrevBPos) {
637  BPos = PrevBPos + 1; }
638  BucketEndV.Add(floor(BPos));
639  }
640  //printf("buckets:\n"); for (int i = 0; i < BucketEndV.Len(); i++) { printf("\t%g\n", BucketEndV[i]);}
641  ExpXYValV.Gen(BucketEndV.Len(), 0);
642  int CurB = 0;
643  double AvgPos=0, Cnt=0, AvgVal=0;
644  for (int v = 0; v < XYValV.Len(); v++) {
645  if (XYValV[v].Key() == 0.0) { continue; }
646  AvgPos += XYValV[v].Key ;//* XYValV[v].Dat; // x
647  AvgVal += XYValV[v].Dat; // y
648  Cnt++;
649  if (v+1 == XYValV.Len() || XYValV[v+1].Key > BucketEndV[CurB]) {
650  if (Cnt != 0) {
651  //AvgPos /= AvgVal;
652  //AvgVal /= (BucketEndV[CurB]-BucketEndV[CurB-1]);
653  AvgPos /= (double) Cnt;
654  AvgVal /= (double) Cnt;
655  if (AvgVal < MinYVal) { AvgVal = MinYVal; }
656  ExpXYValV.Add(TFltKd(AvgPos, AvgVal));
657  //printf("b: %6.2f\t%6.2f\n", AvgPos, AvgVal);
658  AvgPos = 0; AvgVal = 0; Cnt = 0;
659  }
660  CurB++;
661  }
662  }
663 }
#define IAssert(Cond)
Definition: bd.h:262
unsigned int uint
Definition: bd.h:11
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
Definition: dt.h:1293
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:971
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:551
TKey Key
Definition: ds.h:347
bool IsSorted(const bool &Asc=true) const
Checks whether the vector is sorted in ascending (if Asc=true) or descending (if Asc=false) order...
Definition: ds.h:1259
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:495
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
TGnuPlot & TGnuPlot::operator= ( const TGnuPlot GnuPlot)

Definition at line 106 of file gnuplot.cpp.

106  {
107  if (this != &GnuPlot) {
108  DataFNm = GnuPlot.DataFNm;
109  PlotFNm = GnuPlot.PlotFNm;
110  Title = GnuPlot.Title;
111  LblX = GnuPlot.LblX;
112  LblY = GnuPlot.LblY;
113  ScaleTy = GnuPlot.ScaleTy;
114  YRange = GnuPlot.YRange;
115  XRange = GnuPlot.XRange;
116  SetGrid = GnuPlot.SetGrid;
117  SetPause = GnuPlot.SetPause;
118  SeriesV = GnuPlot.SeriesV;
119  MoreCmds = GnuPlot.MoreCmds;
120  }
121  return *this;
122 }
TFltPr XRange
Definition: gnuplot.h:53
TStr Title
Definition: gnuplot.h:51
TStr DataFNm
Definition: gnuplot.h:50
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
bool SetPause
Definition: gnuplot.h:54
bool SetGrid
Definition: gnuplot.h:54
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TStr LblX
Definition: gnuplot.h:51
TFltPr YRange
Definition: gnuplot.h:53
TStr PlotFNm
Definition: gnuplot.h:50
TStrV MoreCmds
Definition: gnuplot.h:56
void TGnuPlot::Pause ( const bool &  DoPause)
inline

Definition at line 77 of file gnuplot.h.

77 { SetPause = DoPause; }
bool SetPause
Definition: gnuplot.h:54
void TGnuPlot::Plot ( const TStr Comment = TStr())
inline

Definition at line 126 of file gnuplot.h.

126 { CreatePlotFile(Comment); RunGnuPlot(); }
void RunGnuPlot() const
Definition: gnuplot.cpp:873
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:768
template<class TVal2 >
void TGnuPlot::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 
)
static

Definition at line 658 of file gnuplot.h.

659  {
661  CntH.GetKeyDatPrV(TmpV);
662  PlotValOverTm(TmpV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, SeriesTy);
663 }
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)
Definition: gnuplot.h:628
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const
Definition: hash.h:458
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TKey , class TVal , class THashFunc >
void TGnuPlot::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 
)
static

Definition at line 434 of file gnuplot.h.

436  {
437  TFltPrV IdCntV(ValCntH.Len(), 0), BucketV;
438  for (int i = ValCntH.FFirstKeyId(); ValCntH.FNextKeyId(i); ) {
439  IdCntV.Add(TFltPr(double(ValCntH.GetKey(i)), double(ValCntH[i]))); }
440  IdCntV.Sort();
441  if (ExpBucket) {
442  TGnuPlot::MakeExpBins(IdCntV, BucketV);
443  BucketV.Swap(IdCntV);
444  }
445  if (PlotCCDF) {
446  TFltPrV NCdfV = IdCntV;
447  for (int i = NCdfV.Len()-2; i >= 0; i--) {
448  NCdfV[i].Val2 = NCdfV[i].Val2 + NCdfV[i+1].Val2;
449  }
450  PlotValV(NCdfV, OutFNmPref, Desc, "NCDF "+XLabel, "NCDF "+YLabel, ScaleTy, PowerFit, SeriesTy);
451  } else {
452  PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
453  }
454 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:614
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int Len() const
Definition: hash.h:186
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)
Definition: gnuplot.h:398
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TKey , class TVal , class THashFunc >
void TGnuPlot::PlotValCntH ( const THash< TKey, TVal, THashFunc > &  ValCntH1,
const TStr Label1,
const THash< TKey, TVal, THashFunc > &  ValCntH2,
const TStr Label2,
const TStr OutFNmPref,
const TStr Desc,
const TStr XLabel,
const TStr YLabel,
const TGpScaleTy ScaleTy = gpsAuto,
const TGpSeriesTy SeriesTy = gpwLinesPoints 
)
static

Definition at line 457 of file gnuplot.h.

460  {
461  PlotValCntH(ValCntH1, Label1, ValCntH2, Label2, THash<TKey, TVal, THashFunc>(), "", OutFNmPref, Desc, XLabel, YLabel,
462  ScaleTy, SeriesTy);
463 }
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
Definition: hash.h:88
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)
Definition: gnuplot.h:434
template<class TKey , class TVal , class THashFunc >
void TGnuPlot::PlotValCntH ( const THash< TKey, TVal, THashFunc > &  ValCntH1,
const TStr Label1,
const THash< TKey, TVal, THashFunc > &  ValCntH2,
const TStr Label2,
const THash< TKey, TVal, THashFunc > &  ValCntH3,
const TStr Label3,
const TStr OutFNmPref,
const TStr Desc,
const TStr XLabel,
const TStr YLabel,
const TGpScaleTy ScaleTy = gpsAuto,
const TGpSeriesTy SeriesTy = gpwLinesPoints 
)
static

Definition at line 466 of file gnuplot.h.

470  {
471  TFltPrV IdCntV1(ValCntH1.Len(), 0), IdCntV2(ValCntH2.Len(), 0), IdCntV3(ValCntH3.Len(), 0);
472  for (int i = ValCntH1.FFirstKeyId(); ValCntH1.FNextKeyId(i); ) {
473  IdCntV1.Add(TFltPr(double(ValCntH1.GetKey(i)), double(ValCntH1[i]))); }
474  for (int i = ValCntH2.FFirstKeyId(); ValCntH2.FNextKeyId(i); ) {
475  IdCntV2.Add(TFltPr(double(ValCntH2.GetKey(i)), double(ValCntH2[i]))); }
476  for (int i = ValCntH3.FFirstKeyId(); ValCntH3.FNextKeyId(i); ) {
477  IdCntV3.Add(TFltPr(double(ValCntH3.GetKey(i)), double(ValCntH3[i]))); }
478  IdCntV1.Sort();
479  IdCntV2.Sort();
480  IdCntV3.Sort();
481  TGnuPlot GP(OutFNmPref, Desc);
482  GP.SetXYLabel(XLabel, YLabel);
483  GP.SetScale(ScaleTy);
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); }
487  GP.SavePng();
488 }
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int Len() const
Definition: hash.h:186
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TVal1 >
void TGnuPlot::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 
)
static

Definition at line 491 of file gnuplot.h.

494  {
495  TFltTrV AvgV, StdErrV;
496  TFltPrV AvgV2, MedV, MinV, MaxV;
497  TFltPrV ScatterV;
498  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
499  TMom Mom(ValMomH[i]);
500  if (! Mom.IsDef()) { Mom.Def(); }
501  const double x = ValMomH.GetKey(i);
502  if (PlotAvg) {
503  if (PlotSDev) {
504  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
505  else {
506  AvgV2.Add(TFltPr(x, Mom.GetMean()));
507  }
508  if (PlotStdErr) {
509  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
510  }
511  }
512  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
513  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
514  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
515  if (PlotScatter) {
516  THashSet<TFlt> PointSet;
517  for (int xi = 0; xi < ValMomH[i].GetVals(); xi++) {
518  PointSet.AddKey(ValMomH[i].GetVal(xi)); }
519  //ScatterV.Add(TFltPr(x, ValMomH[i].GetVal(xi))); }
520  for (int xi = 0; xi < PointSet.Len(); xi++) {
521  ScatterV.Add(TFltPr(x, PointSet[xi])); }
522  //printf("S%d %d %d.", ValMomH[i].GetVals(), PointSet.Len(), ScatterV.Len());
523  }
524  }
525  AvgV.Sort(); AvgV2.Sort();
526  MedV.Sort(); MinV.Sort(); MaxV.Sort(); StdErrV.Sort();
527  TGnuPlot GP(OutFNmPref, Desc);
528  GP.SetScale(ScaleTy);
529  GP.SetXYLabel(XLabel, YLabel);
530  if (! ScatterV.Empty()) { GP.AddPlot(ScatterV, gpwPoints, "Scatter"); }
531  if (! AvgV.Empty()) { GP.AddErrBar(AvgV, "Average", "StdDev"); }
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"); }
537  GP.SavePng();
538 }
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1254
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int AddKey(const TKey &Key)
Definition: shash.h:1254
int FFirstKeyId() const
Definition: hash.h:236
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:180
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
int Len() const
Definition: shash.h:1121
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TVal1 >
void TGnuPlot::PlotValMomH ( const THash< TVal1, TMom > &  ValMomH1,
const TStr Label1,
const THash< TVal1, TMom > &  ValMomH2,
const TStr Label2,
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 
)
static

Definition at line 541 of file gnuplot.h.

545  {
546  TFltTrV AvgV1, AvgV2, StdErrV1, StdErrV2;
547  TFltPrV AvgVM1, MedV1, MinV1, MaxV1;
548  TFltPrV AvgVM2, MedV2, MinV2, MaxV2;
549  TFltPrV ScatterV1, ScatterV2;
550  // ValMom1
551  for (int i = ValMomH1.FFirstKeyId(); ValMomH1.FNextKeyId(i); ) {
552  TMom Mom(ValMomH1[i]);
553  if (! Mom.IsDef()) { Mom.Def(); }
554  const double x = ValMomH1.GetKey(i);
555  if (PlotAvg) {
556  if (PlotSDev) {
557  AvgV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
558  else {
559  AvgVM1.Add(TFltPr(x, Mom.GetMean()));
560  }
561  if (PlotStdErr) {
562  StdErrV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
563  }
564  }
565  if (PlotMed) { MedV1.Add(TFltPr(x, Mom.GetMedian())); }
566  if (PlotMin) { MinV1.Add(TFltPr(x, Mom.GetMn())); }
567  if (PlotMax) { MaxV1.Add(TFltPr(x, Mom.GetMx())); }
568  if (PlotScatter) {
569  THashSet<TFlt> PointSet;
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])); }
574  }
575  }
576  AvgV1.Sort(); AvgVM1.Sort(); MedV1.Sort(); MinV1.Sort(); MaxV1.Sort(); StdErrV1.Sort();
577  // ValMom2
578  for (int i = ValMomH2.FFirstKeyId(); ValMomH2.FNextKeyId(i); ) {
579  TMom Mom(ValMomH2[i]);
580  if (! Mom.IsDef()) { Mom.Def(); }
581  const double x = ValMomH2.GetKey(i);
582  if (PlotAvg) {
583  if (PlotSDev) {
584  AvgV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
585  else {
586  AvgVM2.Add(TFltPr(x, Mom.GetMean()));
587  }
588  if (PlotStdErr) {
589  StdErrV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
590  }
591  }
592  if (PlotMed) { MedV2.Add(TFltPr(x, Mom.GetMedian())); }
593  if (PlotMin) { MinV2.Add(TFltPr(x, Mom.GetMn())); }
594  if (PlotMax) { MaxV2.Add(TFltPr(x, Mom.GetMx())); }
595  if (PlotScatter) {
596  THashSet<TFlt> PointSet;
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])); }
601  }
602  }
603  AvgV2.Sort(); AvgVM2.Sort(); MedV2.Sort(); MinV2.Sort(); MaxV2.Sort(); StdErrV2.Sort();
604  // plot
605  TGnuPlot GP(OutFNmPref, Desc);
606  GP.SetScale(ScaleTy);
607  GP.SetXYLabel(XLabel, YLabel);
608  // ValMom1
609  if (! ScatterV1.Empty()) { GP.AddPlot(ScatterV1, gpwPoints, Label1+": Scatter"); }
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"); }
616  // ValMom2
617  if (! ScatterV2.Empty()) { GP.AddPlot(ScatterV2, gpwPoints, Label2+": Scatter"); }
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"); }
624  GP.SavePng();
625 }
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1254
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int AddKey(const TKey &Key)
Definition: shash.h:1254
int FFirstKeyId() const
Definition: hash.h:236
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:180
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
int Len() const
Definition: shash.h:1121
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TVal2 >
void TGnuPlot::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 
)
static

Definition at line 628 of file gnuplot.h.

629  {
630  if (ValV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
631  TVec<TPair<TSecTm, TVal2> > TmpV = ValV;
632  TmpV.Sort();
633  TGnuPlot GP(OutFNmPref, Desc);
634  GP.SetXYLabel(XLabel, YLabel);
635  GP.SetScale(ScaleTy);
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\"");
639 
640  // save file
641  time_t ltime; time(&ltime);
642  char* TimeStr = ctime(&ltime); TimeStr[strlen(TimeStr) - 1] = 0;
643  FILE *F = fopen(GP.DataFNm.CStr(), "wt");
644  fprintf(F, "#\n");
645  fprintf(F, "# %s (%s)\n", Desc.CStr(), TimeStr);
646  fprintf(F, "#\n");
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()));
650  }
651  fclose(F);
652  // plot data
653  GP.AddPlot(GP.DataFNm, 1, 2);
654  GP.SavePng();
655 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:542
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1254
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
char * CStr()
Definition: dt.h:476
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TKey , class TVal , class THashFunc >
void TGnuPlot::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 
)
static

Definition at line 420 of file gnuplot.h.

421  {
422  TFltPrV IdCntV(ValCntH.Len(), 0);
423  TFltV ValV(ValCntH.Len(), 0);
424  for (int i = ValCntH.FFirstKeyId(); ValCntH.FNextKeyId(i); ) {
425  ValV.Add(double(ValCntH[i])); }
426  ValV.Sort(false);
427  for (int i = 0; i < ValV.Len(); i++) {
428  IdCntV.Add(TFltPr(i+1, ValV[i]));
429  }
430  PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
431 }
bool FNextKeyId(int &KeyId) const
Definition: hash.h:436
int FFirstKeyId() const
Definition: hash.h:236
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
int Len() const
Definition: hash.h:186
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)
Definition: gnuplot.h:398
Vector is a sequence TVal objects representing an array that can change in size.
Definition: ds.h:429
template<class TVal1 >
void TGnuPlot::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 
)
static

Definition at line 398 of file gnuplot.h.

399  {
400  TFltKdV IdCntV(ValV.Len(), 0);
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; }
404  IdCntV.Sort();
405  TGnuPlot GP(OutFNmPref, Desc);
406  GP.SetXYLabel(XLabel, YLabel);
407  GP.SetScale(ScaleTy);
408  const int Id = GP.AddPlot(IdCntV, SeriesTy);
409  if (PowerFit) {
410  GP.AddPwrFit3(Id);
411  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
412  if (MaxY < MinY) { Swap(MaxY, MinY); }
413  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
414  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
415  }
416  GP.SavePng();
417 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
template<class TVal1 , class TVal2 >
void TGnuPlot::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

Definition at line 316 of file gnuplot.h.

317  {
318  TFltKdV IdCntV(ValV.Len(), 0);
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; }
322  IdCntV.Sort();
323  TGnuPlot GP(OutFNmPref, Desc);
324  GP.SetXYLabel(XLabel, YLabel);
325  GP.SetScale(ScaleTy);
326  const int Id = GP.AddPlot(IdCntV, SeriesTy);
327  if (PowerFit) {
328  GP.AddPwrFit3(Id);
329  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
330  if (MaxY < MinY) { Swap(MaxY, MinY); }
331  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
332  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
333  }
334  GP.SavePng();
335 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
template<class TVal1 , class TVal2 , class TVal3 >
void TGnuPlot::PlotValV ( const TVec< TTriple< TVal1, TVal2, TVal3 > > &  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 TStr ErrBarStr = "" 
)
static

Definition at line 338 of file gnuplot.h.

340  {
341  TFltKdV IdCntV(ValV.Len(), 0);
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));
346  }
347  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
348  IdCntV.Sort();
349  TGnuPlot GP(OutFNmPref, Desc);
350  GP.SetXYLabel(XLabel, YLabel);
351  GP.SetScale(ScaleTy);
352  const int Id = GP.AddPlot(IdCntV, SeriesTy);
353  GP.AddErrBar(IdCntV, DeltaYV, ErrBarStr);
354  if (PowerFit) {
355  GP.AddPwrFit3(Id);
356  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
357  if (MaxY < MinY) { Swap(MaxY, MinY); }
358  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
359  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
360  }
361  GP.SavePng();
362 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
template<class TVal1 , class TVal2 >
void TGnuPlot::PlotValV ( const TVec< TPair< TVal1, TVal2 > > &  ValV1,
const TStr Name1,
const TVec< TPair< TVal1, TVal2 > > &  ValV2,
const TStr Name2,
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

Definition at line 365 of file gnuplot.h.

368  {
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; }
375  IdCntV1.Sort();
376  IdCntV2.Sort();
377  TGnuPlot GP(OutFNmPref, Desc);
378  GP.SetXYLabel(XLabel, YLabel);
379  GP.SetScale(ScaleTy);
380  { const int Id = GP.AddPlot(IdCntV1, SeriesTy, Name1);
381  if (PowerFit) {
382  GP.AddPwrFit3(Id);
383  double MaxY = IdCntV1.Last().Dat, MinY = IdCntV1[0].Dat;
384  if (MaxY < MinY) { Swap(MaxY, MinY); }
385  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
386  } }
387  { const int Id = GP.AddPlot(IdCntV2, SeriesTy, Name2);
388  if (PowerFit) {
389  GP.AddPwrFit3(Id);
390  double MaxY = IdCntV2.Last().Dat, MinY = IdCntV2[0].Dat;
391  if (MaxY < MinY) { Swap(MaxY, MinY); }
392  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
393  } }
394  GP.SavePng();
395 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:395
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
void TGnuPlot::RunGnuPlot ( ) const

Definition at line 873 of file gnuplot.cpp.

873  {
874  // try running gnuplot
875  if (system(TStr::Fmt("%s %s", GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
876  if (! GnuPlotPath.Empty()) {
877  #if defined(GLib_WIN)
878  if (system(TStr::Fmt("%s\\%s %s", GnuPlotPath.CStr(), GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
879  #else
880  if (system(TStr::Fmt("%s/%s %s", GnuPlotPath.CStr(), GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
881  #endif
882  }
883  //Old
884  //#if defined(GLib_WIN)
885  //if (system(TStr::Fmt(".\\%s %s", GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
886  //#else
887  //if (system(TStr::Fmt("./%s %s", GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
888  //#endif
889  //if (system(TStr::Fmt("%s%s %s", GpPath.CStr(), GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
890  //FailR(TStr::Fmt("Cannot find GnuPlot (%s) for plot %s. Set the PATH.", GpFNm.CStr(), PlotFNm.CStr()).CStr());
891  //ErrNotify(TStr::Fmt("Cannot find GnuPlot (%s) for plot %s. Set the PATH.", GpFNm.CStr(), PlotFNm.CStr()).CStr());
892  fprintf(stderr, "[%s:%d] Cannot find GnuPlot (%s) for plot %s. Set the $$PATH variable or TGnuPlot::GnuPlotPath. (%s)\n", __FILE__, __LINE__, GnuPlotFNm.CStr(), PlotFNm.CStr(), TGnuPlot::GnuPlotPath.CStr());
893 }
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
static TStr GnuPlotPath
Path to GnuPlot executable. Set if gnuplot is not found in the PATH.
Definition: gnuplot.h:19
char * CStr()
Definition: dt.h:476
static TStr GnuPlotFNm
GnuPlot executable file name. Set if different than the standard wgnuplot/gnuplot.
Definition: gnuplot.h:21
TStr PlotFNm
Definition: gnuplot.h:50
void TGnuPlot::SaveEps ( const int &  FontSz = 30,
const TStr Comment = TStr() 
)
inline

Definition at line 123 of file gnuplot.h.

123  {
124  SaveEps(PlotFNm.GetFPath()+PlotFNm.GetFMid()+".eps", FontSz, Comment); }
TStr GetFMid() const
Definition: dt.cpp:1403
TStr GetFPath() const
Definition: dt.cpp:1389
void SaveEps(const int &FontSz=30, const TStr &Comment=TStr())
Definition: gnuplot.h:123
TStr PlotFNm
Definition: gnuplot.h:50
void TGnuPlot::SaveEps ( const TStr FNm,
const int &  FontSz = 30,
const TStr Comment = TStr() 
)

Definition at line 604 of file gnuplot.cpp.

604  {
605  AddCmd(TStr::Fmt("set terminal postscript enhanced eps %d color", FontSz));
606  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
607  Pause(false);
608  CreatePlotFile(Comment.Empty()? Title : Comment);
609  RunGnuPlot();
610  MoreCmds.DelLast();
611  MoreCmds.DelLast();
612 }
TStr Title
Definition: gnuplot.h:51
void AddCmd(const TStr &Cmd)
Definition: gnuplot.h:81
void Pause(const bool &DoPause)
Definition: gnuplot.h:77
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
void RunGnuPlot() const
Definition: gnuplot.cpp:873
void DelLast()
Removes the last element of the vector.
Definition: ds.h:635
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:768
TStrV MoreCmds
Definition: gnuplot.h:56
void TGnuPlot::SavePng ( const int &  SizeX = 1000,
const int &  SizeY = 800,
const TStr Comment = TStr() 
)
inline

Definition at line 120 of file gnuplot.h.

120  {
121  SavePng(PlotFNm.GetFPath()+PlotFNm.GetFMid()+".png", SizeX, SizeY, Comment); }
TStr GetFMid() const
Definition: dt.cpp:1403
TStr GetFPath() const
Definition: dt.cpp:1389
void SavePng(const int &SizeX=1000, const int &SizeY=800, const TStr &Comment=TStr())
Definition: gnuplot.h:120
TStr PlotFNm
Definition: gnuplot.h:50
void TGnuPlot::SavePng ( const TStr FNm,
const int &  SizeX = 1000,
const int &  SizeY = 800,
const TStr Comment = TStr(),
const TStr Terminal = TStr() 
)

Definition at line 582 of file gnuplot.cpp.

582  {
583  if (Terminal.Empty()) {
584  //#ifdef GLib_WIN
585  //#ifndef GLib_MACOSX // The standard GNUPlot for MacOS does not support PNG (Jure: actually version 4.6 DOES!)
586  // RS 2014/06/17 standard GNUPlot is tricky to configure for PNG on MacOS
587  AddCmd(TStr::Fmt("set terminal png font arial 10 size %d,%d", SizeX, SizeY));
588  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
589  //#else // EPS
590  //AddCmd("set terminal postscript eps 10 enhanced color");
591  //AddCmd(TStr::Fmt("set output '%s%s.eps'", FNm.GetFPath().CStr(), FNm.GetFMid().CStr()));
592  //#endif
593  } else {
594  AddCmd(Terminal);
595  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
596  }
597  Pause(false);
598  CreatePlotFile(Comment.Empty()? Title : Comment);
599  RunGnuPlot();
600  MoreCmds.DelLast();
601  MoreCmds.DelLast();
602 }
TStr Title
Definition: gnuplot.h:51
void AddCmd(const TStr &Cmd)
Definition: gnuplot.h:81
void Pause(const bool &DoPause)
Definition: gnuplot.h:77
bool Empty() const
Definition: dt.h:488
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
char * CStr()
Definition: dt.h:476
void RunGnuPlot() const
Definition: gnuplot.cpp:873
void DelLast()
Removes the last element of the vector.
Definition: ds.h:635
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:768
TStrV MoreCmds
Definition: gnuplot.h:56
void TGnuPlot::SaveTs ( const TIntKdV KdV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 717 of file gnuplot.cpp.

717  {
718  FILE *F = fopen(FNm.CStr(), "wt");
719  EAssert(F);
720  if (! HeadLn.Empty()) fprintf(F, "# %s\n", HeadLn.CStr());
721  for (int i = 0; i < KdV.Len(); i++) {
722  fprintf(F, "%d\t%d\n", KdV[i].Key(), KdV[i].Dat()); }
723  fclose(F);
724 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
char * CStr()
Definition: dt.h:476
void TGnuPlot::SaveTs ( const TIntFltKdV KdV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 727 of file gnuplot.cpp.

727  {
728  FILE *F = fopen(FNm.CStr(), "wt");
729  EAssert(F);
730  if (! HeadLn.Empty()) fprintf(F, "# %s\n", HeadLn.CStr());
731  for (int i = 0; i < KdV.Len(); i++)
732  fprintf(F, "%d\t%g\n", KdV[i].Key(), KdV[i].Dat());
733  fclose(F);
734 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
char * CStr()
Definition: dt.h:476
template<class TVal1 , class TVal2 >
void TGnuPlot::SaveTs ( const TVec< TPair< TVal1, TVal2 > > &  ValV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 226 of file gnuplot.h.

226  {
227  FILE *F = fopen(FNm.CStr(), "wt");
228  EAssert(F);
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)); }
232  fclose(F);
233 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
char * CStr()
Definition: dt.h:476
template<class TVal1 , class TVal2 , class TVal3 >
void TGnuPlot::SaveTs ( const TVec< TTriple< TVal1, TVal2, TVal3 > > &  ValV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 236 of file gnuplot.h.

236  {
237  FILE *F = fopen(FNm.CStr(), "wt");
238  EAssert(F);
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)); }
242  fclose(F);
243 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
char * CStr()
Definition: dt.h:476
template<class TVal , int Vals>
void TGnuPlot::SaveTs ( const TVec< TTuple< TVal, Vals > > &  ValV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 246 of file gnuplot.h.

246  {
247  FILE *F = fopen(FNm.CStr(), "wt");
248  EAssert(F);
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])); }
254  fprintf(F, "\n");
255  }
256  fclose(F);
257 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:547
#define EAssert(Cond)
Definition: bd.h:280
bool Empty() const
Definition: dt.h:488
char * CStr()
Definition: dt.h:476
void TGnuPlot::SetDataPlotFNm ( const TStr DatFNm,
const TStr PltFNm 
)
inline

Definition at line 74 of file gnuplot.h.

74 { DataFNm = DatFNm; PlotFNm = PltFNm; }
TStr DataFNm
Definition: gnuplot.h:50
TStr PlotFNm
Definition: gnuplot.h:50
void TGnuPlot::SetLineStyle ( const int &  PlotId,
const TStr StyleStr 
)
inline

Definition at line 83 of file gnuplot.h.

83 { SeriesV[PlotId].WithStyle = StyleStr; }
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
void TGnuPlot::SetScale ( const TGpScaleTy GpScaleTy)
inline

Definition at line 78 of file gnuplot.h.

78 { ScaleTy = GpScaleTy;}
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
void TGnuPlot::SetTitle ( const TStr PlotTitle)
inline

Definition at line 70 of file gnuplot.h.

70 { Title = PlotTitle; }
TStr Title
Definition: gnuplot.h:51
void TGnuPlot::SetXLabel ( const TStr XLabel)
inline

Definition at line 71 of file gnuplot.h.

71 { LblX = XLabel; }
TStr LblX
Definition: gnuplot.h:51
void TGnuPlot::SetXRange ( const double &  Min,
const double &  Max 
)
inline

Definition at line 79 of file gnuplot.h.

79 { XRange = TFltPr(Min, Max); }
TFltPr XRange
Definition: gnuplot.h:53
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
void TGnuPlot::SetXYLabel ( const TStr XLabel,
const TStr YLabel 
)
inline

Definition at line 73 of file gnuplot.h.

73 { LblX = XLabel; LblY = YLabel; }
TStr LblY
Definition: gnuplot.h:51
TStr LblX
Definition: gnuplot.h:51
void TGnuPlot::SetYLabel ( const TStr YLabel)
inline

Definition at line 72 of file gnuplot.h.

72 { LblY = YLabel; }
TStr LblY
Definition: gnuplot.h:51
void TGnuPlot::SetYRange ( const double &  Min,
const double &  Max 
)
inline

Definition at line 80 of file gnuplot.h.

80 { YRange = TFltPr(Min, Max); }
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TFltPr YRange
Definition: gnuplot.h:53
void TGnuPlot::ShowGrid ( const bool &  Show)
inline

Definition at line 76 of file gnuplot.h.

76 { SetGrid = Show; }
bool SetGrid
Definition: gnuplot.h:54
void TGnuPlot::Test ( )
static

Definition at line 736 of file gnuplot.cpp.

736  {
737  TFltV DeltaY;
738  TFltPrV ValV1, ValV2, ValV3;
739  for (int i = 1; i < 30; i++) {
740  ValV1.Add(TFltPr(i, pow(double(i), 1.2)));
741  DeltaY.Add(5*TInt::Rnd.GetUniDev());
742  ValV2.Add(TFltPr(i, 5*i-1));
743  }
744  for (int i = -10; i < 20; i++) {
745  ValV3.Add(TFltPr(i, 2*i + 2 + TInt::Rnd.GetUniDev()));
746  }
747  TGnuPlot GnuPlot("testDat", "TestPlot", true);
748  GnuPlot.SetXYLabel("X", "Y");
749  const int id2 = GnuPlot.AddPlot(ValV2, gpwPoints, "y=5*x-1");
750  const int id3 = GnuPlot.AddPlot(ValV3, gpwPoints, "y=2*x+2");
751  GnuPlot.AddErrBar(ValV1, DeltaY, "y=x^2", "Error bar");
752  GnuPlot.AddLinFit(id2, gpwLines);
753  GnuPlot.AddLinFit(id3, gpwLines);
754  GnuPlot.Plot();
755  GnuPlot.SavePng("testPlot.png");
756 }
static TRnd Rnd
Definition: dt.h:1053
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:574

Member Data Documentation

TStr TGnuPlot::DataFNm
private

Definition at line 50 of file gnuplot.h.

TStr TGnuPlot::DefDataFNm = "GnuPlot.tab"
static

Definition at line 23 of file gnuplot.h.

TStr TGnuPlot::DefPlotFNm = "GnuPlot.plt"
static

Definition at line 22 of file gnuplot.h.

TStr TGnuPlot::GnuPlotFNm = "gnuplot"
static

GnuPlot executable file name. Set if different than the standard wgnuplot/gnuplot.

Definition at line 21 of file gnuplot.h.

TStr TGnuPlot::GnuPlotPath = "/usr/bin"
static

Path to GnuPlot executable. Set if gnuplot is not found in the PATH.

Definition at line 19 of file gnuplot.h.

TStr TGnuPlot::LblX
private

Definition at line 51 of file gnuplot.h.

TStr TGnuPlot::LblY
private

Definition at line 51 of file gnuplot.h.

TStrV TGnuPlot::MoreCmds
private

Definition at line 56 of file gnuplot.h.

TStr TGnuPlot::PlotFNm
private

Definition at line 50 of file gnuplot.h.

TGpScaleTy TGnuPlot::ScaleTy
private

Definition at line 52 of file gnuplot.h.

TVec<TGpSeries> TGnuPlot::SeriesV
private

Definition at line 55 of file gnuplot.h.

bool TGnuPlot::SetGrid
private

Definition at line 54 of file gnuplot.h.

bool TGnuPlot::SetPause
private

Definition at line 54 of file gnuplot.h.

int TGnuPlot::Tics42 = -2
staticprivate

Definition at line 48 of file gnuplot.h.

TStr TGnuPlot::Title
private

Definition at line 51 of file gnuplot.h.

TFltPr TGnuPlot::XRange
private

Definition at line 53 of file gnuplot.h.

TFltPr TGnuPlot::YRange
private

Definition at line 53 of file gnuplot.h.


The documentation for this class was generated from the following files: