SNAP Library 2.4, User Reference  2015-05-11 19:40:56
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 , 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 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 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 &PlotNCDF=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)
 

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:559
TStrV MoreCmds
Definition: gnuplot.h:56
int TGnuPlot::AddErrBar ( const TFltTrV XYDValV,
const TStr Label = TStr() 
)

Definition at line 261 of file gnuplot.cpp.

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

Definition at line 271 of file gnuplot.cpp.

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

Definition at line 283 of file gnuplot.cpp.

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

Definition at line 292 of file gnuplot.cpp.

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

Definition at line 302 of file gnuplot.cpp.

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

Definition at line 320 of file gnuplot.cpp.

320  {
321  if (XYValV.Empty()) {
322  printf("***AddErrBar: empty plot (%s) %s\n", DataFNm.CStr(), Title.CStr());
323  return -1;
324  }
325  IAssert(XYValV.Len() == DeltaYV.Len());
326  TGpSeries Plot;
327  Plot.SeriesTy = gpwErrBars;
328  Plot.Label = Label;
329  Plot.XYValV = XYValV;
330  Plot.ZValV = DeltaYV;
331  SeriesV.Add(Plot);
332  return SeriesV.Len() - 1;
333 }
#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:535
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:530
char * CStr()
Definition: dt.h:476
int TGnuPlot::AddErrBar ( const TFltPrV XYValV,
const TFltV DeltaYV,
const TStr DatLabel,
const TStr ErrLabel 
)

Definition at line 310 of file gnuplot.cpp.

310  {
311  TFltKdV XYFltValV(XYValV.Len(), 0);
312  for (int i = 0; i < XYValV.Len(); i++) {
313  XYFltValV.Add(TFltKd(XYValV[i].Val1, XYValV[i].Val2));
314  }
315  const int PlotId = AddPlot(XYFltValV, gpwLinesPoints, DatLabel);
316  AddErrBar(XYFltValV, DeltaV, ErrLabel);
317  return PlotId;
318 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:261
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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 546 of file gnuplot.cpp.

546  {
547  const TGpSeries& Plot = SeriesV[PlotId];
548  if(Plot.XYValV.Empty()) return -1;
549  const TFltKdV& XY = Plot.XYValV;
550  double A, B, R2, SigA, SigB, Chi2;
551  // power fit
552  TFltPrV XYPr;
553  int s;
554  for (s = 0; s < XY.Len(); s++) {
555  if (XY[s].Key-FitXOffset > 0) {
556  XYPr.Add(TFltPr(XY[s].Key-FitXOffset, XY[s].Dat)); }
557  }
558  TSpecFunc::ExpFit(XYPr, A, B, SigA, SigB, Chi2, R2);
559  TStr Label, StyleStr=Style;
560  if (FitXOffset == 0) { Label = TStr::Fmt("%.4g exp(%.4g x) R^2:%.2g", A, B, R2); }
561  else { Label = TStr::Fmt("%.4g exp(%.4g x - %g) R^2:%.2g", A, B, FitXOffset, R2); }
562  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
563  const int FitId = AddFunc(TStr::Fmt("%f*exp(%f*x-%f)", A, B, FitXOffset),
564  SeriesTy, Label, StyleStr);
565  return FitId;
566  /*SeriesV.Add();
567  TGpSeries& NewPlot = SeriesV.Last();
568  TFltKdV& EstXY = NewPlot.XYValV;
569  for (s = 0; s < XYPr.Len(); s++) {
570  EstXY.Add(TFltKd(XYPr[s].Val1+FitXOffset, A*exp(B*XYPr[s].Val1)));
571  }
572  NewPlot.SeriesTy = SeriesTy;
573  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
574  else { NewPlot.WithStyle = Style; }
575  return SeriesV.Len() - 1;*/
576 }
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:535
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:559
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:151
int TGnuPlot::AddFunc ( const TStr FuncStr,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 151 of file gnuplot.cpp.

151  {
152  const int Id = SeriesV.Len();
153  TGpSeries Plot;
154  Plot.SeriesTy = SeriesTy;
155  Plot.Label = Label;
156  if (! FuncStr.Empty()) { Plot.DataFNm = TStr::Fmt("f%d(x)=%s, f%d(x)", Id, FuncStr.CStr(), Id); }
157  else { Plot.DataFNm = TStr::Fmt("f%d(x)", Id); }
158  Plot.XCol = -1;
159  Plot.WithStyle = Style;
160  SeriesV.Add(Plot);
161  return Id;
162 }
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 335 of file gnuplot.cpp.

335  {
336  if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1;
337  const TGpSeries& Plot = SeriesV[PlotId];
338  if(Plot.XYValV.Empty()) return -1;
339  const TFltKdV& XY = Plot.XYValV;
340  double A, B, R2, SigA, SigB, Chi2;
341  // linear fit
342  TFltPrV XYPr;
343  int s;
344  for (s = 0; s < XY.Len(); s++) {
345  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
346  }
347  TSpecFunc::LinearFit(XYPr, A, B, SigA, SigB, Chi2, R2);
348  TStr StyleStr=Style;
349  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
350  const int FitId = AddFunc(TStr::Fmt("%f+%f*x", A, B),
351  SeriesTy, TStr::Fmt("%.4g + %.4g x R^2:%.2g", A, B, R2), StyleStr);
352  return FitId;
353  /*SeriesV.Add();
354  TGpSeries& NewPlot = SeriesV.Last();
355  TFltKdV& EstXY = NewPlot.XYValV;
356  for (s = 0; s < XY.Len(); s++) {
357  EstXY.Add(TFltKd(XY[s].Key, A + B*XYPr[s].Val1));
358  }
359  NewPlot.Label = TStr::Fmt("%.4g + %.4g x R^2:%.2g", A, B, R2);
360  NewPlot.SeriesTy = SeriesTy;
361  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
362  else { NewPlot.WithStyle = Style; }
363  return SeriesV.Len() - 1;*/
364 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
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:559
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:151
int TGnuPlot::AddLogFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

!! skip zero values

Definition at line 515 of file gnuplot.cpp.

515  {
516  const TGpSeries& Plot = SeriesV[PlotId];
517  if(Plot.XYValV.Empty()) return -1;
518  const TFltKdV& XY = Plot.XYValV;
519  double A, B, R2, SigA, SigB, Chi2;
520  // power fit
521  TFltPrV XYPr;
522  int s;
523  for (s = 0; s < XY.Len(); s++) {
524  if (XY[s].Key > 0) {
525  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat)); }
526  }
527  TSpecFunc::LogFit(XYPr, A, B, SigA, SigB, Chi2, R2);
528  TStr StyleStr=Style;
529  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
530  const int FitId = AddFunc(TStr::Fmt("%f+%f*log(x)", A, B),
531  SeriesTy, TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2), StyleStr);
532  return FitId;
533  /*SeriesV.Add();
534  TGpSeries& NewPlot = SeriesV.Last();
535  TFltKdV& EstXY = NewPlot.XYValV;
536  for (s = 0; s < XYPr.Len(); s++) {
537  EstXY.Add(TFltKd(XYPr[s].Val1, A+B*log((double)XYPr[s].Val1)));
538  }
539  NewPlot.Label = TStr::Fmt("%.4g + %.4g log(x) R^2:%.2g", A, B, R2);
540  NewPlot.SeriesTy = SeriesTy;
541  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
542  else { NewPlot.WithStyle = Style; }
543  return SeriesV.Len() - 1;*/
544 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
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:559
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:151
int TGnuPlot::AddPlot ( const TIntV YValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 182 of file gnuplot.cpp.

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

Definition at line 190 of file gnuplot.cpp.

190  {
191  TFltKdV XYValV(YValV.Len(), 0);
192  for (int i = 0; i < YValV.Len(); i++) {
193  XYValV.Add(TFltKd(TFlt(i+1), TFlt(YValV[i])));
194  }
195  return AddPlot(XYValV, SeriesTy, Label, Style);
196 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TGnuPlot::AddPlot ( const TFltV XValV,
const TFltV YValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 198 of file gnuplot.cpp.

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

Definition at line 207 of file gnuplot.cpp.

207  {
208  TFltKdV XYFltValV(XYValV.Len(), 0);
209  for (int i = 0; i < XYValV.Len(); i++) {
210  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Val1), TFlt(XYValV[i].Val2)));
211  }
212  return AddPlot(XYFltValV, SeriesTy, Label, Style);
213 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TGnuPlot::AddPlot ( const TFltPrV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 215 of file gnuplot.cpp.

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

Definition at line 223 of file gnuplot.cpp.

223  {
224  TFltKdV XYFltValV(XYValV.Len(), 0);
225  for (int i = 0; i < XYValV.Len(); i++) {
226  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Key), TFlt(XYValV[i].Dat)));
227  }
228  return AddPlot(XYFltValV, SeriesTy, Label, Style);
229 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TGnuPlot::AddPlot ( const TFltKdV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 247 of file gnuplot.cpp.

247  {
248  if (XYValV.Empty()) {
249  printf("***AddPlot: empty plot (%s) %s\n", DataFNm.CStr(), Title.CStr());
250  return -1;
251  }
252  TGpSeries Plot;
253  Plot.SeriesTy = SeriesTy;
254  Plot.Label = Label;
255  Plot.XYValV = XYValV;
256  Plot.WithStyle = Style;
257  SeriesV.Add(Plot);
258  return SeriesV.Len() - 1;
259 }
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:530
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 231 of file gnuplot.cpp.

231  {
232  TFltKdV XYFltValV(XYValV.Len(), 0);
233  for (int i = 0; i < XYValV.Len(); i++) {
234  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Key), TFlt(XYValV[i].Dat)));
235  }
236  return AddPlot(XYFltValV, SeriesTy, Label, Style);
237 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TGnuPlot::AddPlot ( const TIntFltPrV XYValV,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 239 of file gnuplot.cpp.

239  {
240  TFltKdV XYFltValV(XYValV.Len(), 0);
241  for (int i = 0; i < XYValV.Len(); i++) {
242  XYFltValV.Add(TFltKd(TFlt(XYValV[i].Val1), TFlt(XYValV[i].Val2)));
243  }
244  return AddPlot(XYFltValV, SeriesTy, Label, Style);
245 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int TGnuPlot::AddPlot ( const TStr DataFNm,
const int &  ColY,
const TGpSeriesTy SeriesTy = gpwLinesPoints,
const TStr Label = TStr(),
const TStr Style = TStr() 
)

Definition at line 164 of file gnuplot.cpp.

165  {
166  return AddPlot(DataFNm, 0, ColY, SeriesTy, Label, Style);
167 }
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:182
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 169 of file gnuplot.cpp.

170  {
171  IAssert(ColY > 0); IAssert(ColX >= 0);
172  TGpSeries Plot;
173  Plot.SeriesTy = SeriesTy;
174  Plot.Label = Label;
175  Plot.DataFNm = DataFNm; Plot.DataFNm.ChangeStrAll("\\", "\\\\");
176  Plot.XCol = ColX; Plot.YCol = ColY; Plot.ZCol = 0;
177  Plot.WithStyle = Style;
178  SeriesV.Add(Plot);
179  return SeriesV.Len() - 1;
180 }
#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 249 of file gnuplot.h.

249  {
250  TFltPrV XYFltValV(XYValH.Len(), 0);
251  for (int k = XYValH.FFirstKeyId(); XYValH.FNextKeyId(k); ) {
252  XYFltValV.Add(TFltPr(TFlt(XYValH.GetKey(k)), TFlt(XYValH[k])));
253  }
254  XYFltValV.Sort();
255  if (ExpBucket) {
256  TFltPrV BucketV;
257  TGnuPlot::MakeExpBins(XYFltValV, BucketV);
258  BucketV.Swap(XYFltValV);
259  }
260  return AddPlot(XYFltValV, SeriesTy, Label, Style);
261 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:610
Definition: dt.h:1291
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1011
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int FFirstKeyId() const
Definition: hash.h:232
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:182
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int Len() const
Definition: hash.h:186
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
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 264 of file gnuplot.h.

264  {
265  TFltTrV AvgV, StdErrV;
266  TFltPrV AvgV2, MedV, MinV, MaxV, BucketV;
267  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
268  TMom Mom(ValMomH[i]);
269  if (! Mom.IsDef()) { Mom.Def(); }
270  const double x = ValMomH.GetKey(i);
271  if (PlotAvg) {
272  if (PlotSDev) {
273  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
274  else if (PlotStdErr) {
275  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
276  } else {
277  AvgV2.Add(TFltPr(x, Mom.GetMean()));
278  }
279  }
280  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
281  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
282  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
283  }
284  AvgV.Sort(); AvgV2.Sort();
285  MedV.Sort(); MinV.Sort(); MaxV.Sort();
286  int PlotId=0;
287  // exponential bucketing
288  if (ExpBucket) {
289  if (! AvgV2.Empty()) { TGnuPlot::MakeExpBins(AvgV2, BucketV); BucketV.Swap(AvgV2); }
290  if (! MedV.Empty()) { TGnuPlot::MakeExpBins(MedV, BucketV); BucketV.Swap(MedV); }
291  if (! MinV.Empty()) { TGnuPlot::MakeExpBins(MinV, BucketV); BucketV.Swap(MinV); }
292  if (! MaxV.Empty()) { TGnuPlot::MakeExpBins(MaxV, BucketV); BucketV.Swap(MaxV); }
293  }
294  // plot
295  if (! AvgV.Empty()) { PlotId = AddErrBar(AvgV, Label+" Average", Label+" StdDev"); }
296  if (! AvgV2.Empty()) { PlotId = AddPlot(AvgV2, SeriesTy, Label+" Average", Style); }
297  if (! MedV.Empty()) { PlotId = AddPlot(MedV, SeriesTy, Label+" Median", Style); }
298  if (! MinV.Empty()) { PlotId = AddPlot(MinV, SeriesTy, Label+" Min", Style); }
299  if (! MaxV.Empty()) { PlotId = AddPlot(MaxV, SeriesTy, Label+" Max", Style); }
300  if (! StdErrV.Empty()) { PlotId = AddErrBar(StdErrV, Label+" Average", Label+" StdErr"); }
301  return PlotId;
302 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:610
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1011
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1218
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int FFirstKeyId() const
Definition: hash.h:232
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:175
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:182
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:261
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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:420
int TGnuPlot::AddPwrFit ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

Definition at line 366 of file gnuplot.cpp.

366  {
367  const int PlotId1 = AddPwrFit3(PlotId, SeriesTy);
368  AddPwrFit2(PlotId, SeriesTy, 5.0);
369  return PlotId1;
370 }
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:463
int AddPwrFit2(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:415
int TGnuPlot::AddPwrFit1 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const TStr Style = TStr() 
)

!! skip zero values

Definition at line 373 of file gnuplot.cpp.

373  {
374  if (PlotId < 0 || PlotId >= SeriesV.Len()) return -1;
375  const TGpSeries& Plot = SeriesV[PlotId];
376  if(Plot.XYValV.Empty()) return -1;
377  const TFltKdV& XY = Plot.XYValV;
378  double A, B, R2, SigA, SigB, Chi2, MinY = TFlt::Mx, MinX = TFlt::Mx;
379  // power fit
380  TFltPrV XYPr;
381  int s;
382  for (s = 0; s < XY.Len(); s++) {
383  if (XY[s].Key > 0) {
384  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
385  MinX = TMath::Mn(MinX, XY[s].Key());
386  MinY = TMath::Mn(MinY, XY[s].Dat());
387  }
388  }
389  MinY = TMath::Mn(1.0, MinY);
390  TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2);
391  TStr StyleStr=Style;
392  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
393  const int FitId = AddFunc(TStr::Fmt("%f*x**%f", A, B),
394  SeriesTy, TStr::Fmt("%.1g * x^{%.4g} R^2:%.2g", A, B, R2), StyleStr);
395  return FitId;
396  /*SeriesV.Add();
397  TGpSeries& NewPlot = SeriesV.Last();
398  const int FitId = SeriesV.Len() - 1;
399  NewPlot.DataFNm = ;
400  TFltKdV& EstXY = NewPlot.XYValV;
401  for (s = 0; s < XYPr.Len(); s++) {
402  const double YVal = A*pow(XYPr[s].Val1(), B);
403  if (YVal < MinY) continue;
404  EstXY.Add(TFltKd(XYPr[s].Val1, YVal));
405  }
406  NewPlot.Label = ;
407  NewPlot.SeriesTy = SeriesTy;
408  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
409  else { NewPlot.WithStyle = Style; }
410  //if (MinX < 5.0) MinX = 5.0;
411  //AddPwrFit2(PlotId, SeriesTy, MinX);*/
412 }
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:535
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static const double Mx
Definition: dt.h:1296
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:559
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:151
int TGnuPlot::AddPwrFit2 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const double &  MinX = -1.0,
const TStr Style = TStr() 
)

Definition at line 415 of file gnuplot.cpp.

415  {
416  const TGpSeries& Plot = SeriesV[PlotId];
417  if(Plot.XYValV.Empty()) return -1;
418  const TFltKdV& XY = Plot.XYValV;
419  // power fit
420  TFltPrV XYPr;
421  double MinY = TFlt::Mx;
422  for (int s = 0; s < XY.Len(); s++) {
423  if (XY[s].Key > 0.0) {
424  XYPr.Add(TFltPr(XY[s].Key, XY[s].Dat));
425  MinY = TMath::Mn(MinY, XY[s].Dat());
426  }
427  }
428  if (XYPr.Empty()) return -1;
429  MinY = TMath::Mn(1.0, MinY);
430  // determine the sign of power coefficient
431  double CoefSign = 0.0;
432  { double A, B, R2, SigA, SigB, Chi2;
433  TSpecFunc::PowerFit(XYPr, A, B, SigA, SigB, Chi2, R2);
434  CoefSign = B > 0.0 ? +1.0 : -1.0; }
435  const double PowerCf = CoefSign * TSpecFunc::GetPowerCoef(XYPr, MinX);
436  int Mid = (int) exp(log((double)XYPr.Len())/2.0);
437  if (Mid >= XYPr.Len()) { Mid = XYPr.Len()-1; }
438  const double MidX = XYPr[Mid].Val1();
439  const double MidY = XYPr[Mid].Val2();
440  const double B = MidY / pow(MidX, PowerCf);
441  TStr StyleStr=Style;
442  if (StyleStr.Empty()) { StyleStr = "linewidth 3"; }
443  const int FitId = AddFunc(TStr::Fmt("%f*x**%f", B, PowerCf),
444  SeriesTy, TStr::Fmt("MLE = x^{%.4g}", PowerCf), StyleStr);
445  return FitId;
446  /*SeriesV.Add();
447  TGpSeries& NewPlot = SeriesV.Last();
448  TFltKdV& XYFit = NewPlot.XYValV;
449  XYFit.Gen(XYPr.Len(), 0);
450  for (int s = 0; s < XYPr.Len(); s++) {
451  const double XVal = XYPr[s].Val1;
452  const double YVal = B * pow(XYPr[s].Val1(), PowerCf);
453  if (YVal < MinY || XVal < MinX) continue;
454  XYFit.Add(TFltKd(XVal, YVal));
455  }
456  NewPlot.Label = TStr::Fmt("PowerFit: %g", PowerCf);
457  NewPlot.SeriesTy = SeriesTy;
458  if (Style.Empty()) { NewPlot.WithStyle = "linewidth 3"; }
459  else { NewPlot.WithStyle = Style; }
460  return SeriesV.Len() - 1;*/
461 }
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:535
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static const double Mx
Definition: dt.h:1296
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
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:559
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:151
int TGnuPlot::AddPwrFit3 ( const int &  PlotId,
const TGpSeriesTy SeriesTy = gpwLines,
const double &  MinX = -1.0,
const TStr Style = TStr() 
)

Definition at line 463 of file gnuplot.cpp.

463  {
464  double Intercept, Slope, R2;
465  return AddPwrFit3(PlotId, SeriesTy, MinX, Style, Intercept, Slope, R2);
466 }
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:463
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 469 of file gnuplot.cpp.

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

Definition at line 764 of file gnuplot.cpp.

764  {
765  time_t ltime; time(&ltime);
766  char* TimeStr = ctime(&ltime); TimeStr[strlen(TimeStr) - 1] = 0;
767  // rearrange columns so that longest are on the left
768  //SeriesV.Sort(false);
769  TIntV SerIdV(SeriesV.Len(), 0);
770  for (int i = 0; i < SeriesV.Len(); i++) { SerIdV.Add(i); }
771  SerIdV.SortCmp(TGpSeriesCmp(SeriesV));
772  // set columns
773  int ColCnt = 1;
774  bool SaveData = false;
775  for (int s = 0; s < SeriesV.Len(); s++) {
776  TGpSeries& Plt = SeriesV[SerIdV[s]];
777  if (Plt.XYValV.Empty()) { continue; }
778  Plt.DataFNm = DataFNm;
779  // plots use same X column
780  const int PrevCol = s > 0 ? IsSameXCol(SerIdV[s], SerIdV[s-1]) : -1;
781  if (PrevCol != -1) { Plt.XCol = PrevCol; }
782  else { Plt.XCol = ColCnt; ColCnt++; }
783  Plt.YCol = ColCnt; ColCnt++;
784  if (! Plt.ZValV.Empty()) { Plt.ZCol = ColCnt; ColCnt++; }
785  if (! Plt.XYValV.Empty()) { SaveData=true; }
786  }
787  // save data file (skip duplicate X columns)
788  if (SaveData) {
789  FILE *F = fopen(DataFNm.CStr(), "wt");
790  EAssertR(F != NULL, TStr("Can not open data file ")+DataFNm);
791  fprintf(F, "#\n");
792  fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
793  fprintf(F, "#\n");
794  // column names
795  for (int i = 0; i < SerIdV.Len(); i++) {
796  const TGpSeries& Ser = SeriesV[SerIdV[i]];
797  if (Ser.XYValV.Empty()) { continue; }
798  if (i == 0) { fprintf(F, "# "); } else { fprintf(F, "\t"); }
799  if (Ser.SaveXVals()) {
800  if (! LblX.Empty()) { fprintf(F, "%s\t", LblX.CStr()); }
801  else { fprintf(F, "XVals\t"); }
802  }
803  if (Ser.Label.Empty()) { fprintf(F, "%s", LblY.CStr()); }
804  else { fprintf(F, "%s", SeriesV[SerIdV[i]].Label.CStr()); }
805  if (Ser.ZCol > 0) fprintf(F, "\tDeltaY");
806  }
807  fprintf(F, "\n");
808  // data
809  for (int row = 0; row < SeriesV[SerIdV[0]].XYValV.Len(); row++) {
810  for (int i = 0; i < SeriesV.Len(); i++) {
811  const TGpSeries& Ser = SeriesV[SerIdV[i]];
812  if (row < Ser.XYValV.Len()) {
813  if (i > 0) { fprintf(F, "\t"); }
814  if (Ser.SaveXVals()) { fprintf(F, "%g\t%g", Ser.XYValV[row].Key(), Ser.XYValV[row].Dat()); }
815  else { fprintf(F, "%g", Ser.XYValV[row].Dat()); }
816  if (! Ser.ZValV.Empty()) { fprintf(F, "\t%g", Ser.ZValV[row]()); }
817  }
818  }
819  fprintf(F, "\n");
820  }
821  fclose(F);
822  }
823  // save plot file
824  FILE *F = fopen(PlotFNm.CStr(), "wt");
825  EAssertR(F != 0, TStr("Can not open plot file ")+PlotFNm);
826  TStr CurDir = TDir::GetCurDir();
827  CurDir.ChangeStrAll("\\", "\\\\");
828  fprintf(F, "#\n");
829  fprintf(F, "# %s (%s)\n", Comment.CStr(), TimeStr);
830  fprintf(F, "#\n\n");
831  if (! Title.Empty()) fprintf(F, "set title \"%s\"\n", Title.CStr());
832  fprintf(F, "set key bottom right\n");
833  fprintf(F, "%s\n", GetScaleStr(ScaleTy).CStr());
835  fprintf(F, "set format x \"10^{%%L}\"\n");
836  fprintf(F, "set mxtics 10\n"); }
838  fprintf(F, "set format y \"10^{%%L}\"\n");
839  fprintf(F, "set mytics 10\n"); }
840  if (ScaleTy==gpsLog2X || ScaleTy==gpsLog2XY) { fprintf(F, "set format x \"2^{%%L}\"\n"); }
841  if (ScaleTy==gpsLog2Y || ScaleTy==gpsLog2XY) { fprintf(F, "set format y \"2^{%%L}\"\n"); }
842  if (SetGrid) fprintf(F, "set grid\n");
843  if (XRange.Val1 != XRange.Val2) fprintf(F, "set xrange [%g:%g]\n", XRange.Val1(), XRange.Val2());
844  if (YRange.Val1 != YRange.Val2) fprintf(F, "set yrange [%g:%g]\n", YRange.Val1(), YRange.Val2());
845  if (! LblX.Empty()) fprintf(F, "set xlabel \"%s\"\n", LblX.CStr());
846  if (! LblY.Empty()) fprintf(F, "set ylabel \"%s\"\n", LblY.CStr());
847  if (Tics42 < -1) {
848  Tics42 = GetTics42();
849  }
850  if (Tics42) {
851  fprintf(F, "set tics scale 2\n"); // New in version 4.2
852  } else {
853  fprintf(F, "set ticscale 2 1\n"); // Old (deprecated)
854  }
855  // custom commands
856  for (int i = 0; i < MoreCmds.Len(); i++) {
857  fprintf(F, "%s\n", MoreCmds[i].CStr()); }
858  // plot
859  if (! SeriesV.Empty()) {
860  fprintf(F, "plot \t");
861  for (int i = 0; i < SeriesV.Len(); i++) {
862  fprintf(F, "%s", GetSeriesPlotStr(i).CStr()); }
863  fprintf(F, "\n");
864  }
865  if (SetPause) fprintf(F, "pause -1 \"Hit return to exit. %s\"\n", PlotFNm.CStr());
866  fclose(F);
867 }
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:535
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:754
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:679
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:559
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 679 of file gnuplot.cpp.

679  {
680  switch(ScaleTy){
681  case gpsNoAuto: return TStr("set noautoscale");
682  case gpsAuto: return TStr("set autoscale");
683  case gpsLog: return TStr("set logscale");
684  case gpsLog2X: return TStr("set logscale x 2");
685  case gpsLog2Y: return TStr("set logscale y 2");
686  case gpsLog2XY: return TStr("set logscale xy 2");
687  case gpsLog10X: return TStr("set logscale x 10");
688  case gpsLog10Y: return TStr("set logscale y 10");
689  case gpsLog10XY: return TStr("set logscale xy 10");
690  default: Fail;
691  }
692  return TStr();
693 }
#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  PlotStr += " title \"" + Series.Label + "\"";
139  // hard coded line style
140  if (Series.WithStyle.Empty()) {
141  if (Series.SeriesTy == gpwLines) Series.WithStyle = "lw 1";
142  if (Series.SeriesTy == gpwPoints) Series.WithStyle = "pt 6"; // circles
143  if (Series.SeriesTy == gpwLinesPoints) Series.WithStyle = "pt 6"; // circles
144  if (Series.SeriesTy == gpwBoxes) Series.WithStyle = "fill solid 0.3";
145  }
146  PlotStr += " with " + GetSeriesTyStr(Series.SeriesTy) + " " + Series.WithStyle;
147  return PlotStr;
148 }
TStr GetStr() const
Definition: dt.h:1105
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
static TStr GetSeriesTyStr(const TGpSeriesTy &SeriesTy)
Definition: gnuplot.cpp:695
Definition: dt.h:201
TStr TGnuPlot::GetSeriesTyStr ( const TGpSeriesTy SeriesTy)
static

Definition at line 695 of file gnuplot.cpp.

695  {
696  switch(SeriesTy) {
697  case gpwLines: return TStr("lines");
698  case gpwPoints: return TStr("points");
699  case gpwLinesPoints: return TStr("linespoints");
700  case gpwImpulses: return TStr("impulses");
701  case gpwDots: return TStr("dots");
702  case gpwSteps: return TStr("steps");
703  case gpwFSteps: return TStr("fsteps");
704  case gpwHiSteps: return TStr("histeps");
705  case gpwBoxes: return TStr("boxes");
706  case gpwErrBars: return TStr("errorbars");
707  case gpwFilledCurves: return TStr("filledcurves");
708  default: Fail;
709  }
710  return TStr();
711 }
#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 754 of file gnuplot.cpp.

754  {
755  //if (SerId < 1) { return -1; }
756  if (SeriesV[CurId].XYValV.Len() != SeriesV[PrevId].XYValV.Len()) { return -1; }
757  for (int x = 0; x < SeriesV[CurId].XYValV.Len(); x++) {
758  if (SeriesV[CurId].XYValV[x] != SeriesV[PrevId].XYValV[x]) { return -1; }
759  }
760  IAssert(SeriesV[PrevId].XCol > 0);
761  return SeriesV[PrevId].XCol;
762 }
#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 661 of file gnuplot.cpp.

661  {
662  PSs Ss = TSs::LoadTxt(ssfTabSep, FNm);
663  int row = 0;
664  ColNmV.Clr();
665  while (Ss->At(0, row)[0] == '#') { row++; }
666  for (int c = 1; c < Ss->GetXLen(row); c+=2) {
667  ColNmV.Add(Ss->At(c, row));
668  }
669  row++;
670  ColV.Gen(ColNmV.Len(), ColNmV.Len());
671  for (; row < Ss->GetYLen(); row++) {
672  for (int c = 0; c < Ss->GetXLen(row); c+=2) {
673  if (Ss->At(c,row).Empty()) break;
674  ColV[c/2].Add(TFltKd(Ss->At(c,row).GetFlt(), Ss->At(c+1,row).GetFlt()));
675  }
676  }
677 }
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:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
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:486
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
void TGnuPlot::MakeExpBins ( const TFltPrV XYValV,
TFltPrV ExpXYValV,
const double &  BinFactor = 2,
const double &  MinYVal = 1 
)
static

Definition at line 610 of file gnuplot.cpp.

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

Definition at line 621 of file gnuplot.cpp.

621  {
622  if (XYValV.Empty()) { ExpXYValV.Clr(false); return; }
623  IAssert(! XYValV.Empty());
624  IAssert(XYValV.IsSorted());
625  const TFlt MxX = XYValV.Last().Key;
626  // find buckets
627  TFltV BucketEndV; BucketEndV.Add(1);
628  double PrevBPos = 1, BPos = 1;
629  while (BPos <= MxX) {
630  PrevBPos = (uint) floor(BPos);
631  BPos *= BinFactor;
632  if (floor(BPos) == PrevBPos) {
633  BPos = PrevBPos + 1; }
634  BucketEndV.Add(floor(BPos));
635  }
636  //printf("buckets:\n"); for (int i = 0; i < BucketEndV.Len(); i++) { printf("\t%g\n", BucketEndV[i]);}
637  ExpXYValV.Gen(BucketEndV.Len(), 0);
638  int CurB = 0;
639  double AvgPos=0, Cnt=0, AvgVal=0;
640  for (int v = 0; v < XYValV.Len(); v++) {
641  if (XYValV[v].Key() == 0.0) { continue; }
642  AvgPos += XYValV[v].Key ;//* XYValV[v].Dat; // x
643  AvgVal += XYValV[v].Dat; // y
644  Cnt++;
645  if (v+1 == XYValV.Len() || XYValV[v+1].Key > BucketEndV[CurB]) {
646  if (Cnt != 0) {
647  //AvgPos /= AvgVal;
648  //AvgVal /= (BucketEndV[CurB]-BucketEndV[CurB-1]);
649  AvgPos /= (double) Cnt;
650  AvgVal /= (double) Cnt;
651  if (AvgVal < MinYVal) { AvgVal = MinYVal; }
652  ExpXYValV.Add(TFltKd(AvgPos, AvgVal));
653  //printf("b: %6.2f\t%6.2f\n", AvgPos, AvgVal);
654  AvgPos = 0; AvgVal = 0; Cnt = 0;
655  }
656  CurB++;
657  }
658  }
659 }
#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:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
Definition: dt.h:1291
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
void Clr(const bool &DoDel=true, const TSizeTy &NoDelLim=-1)
Clears the contents of the vector.
Definition: ds.h:953
const TVal & Last() const
Returns a reference to the last element of the vector.
Definition: ds.h:539
TKey Key
Definition: ds.h:338
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:1223
void Gen(const TSizeTy &_Vals)
Constructs a vector (an array) of _Vals elements.
Definition: ds.h:486
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
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:869
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:764
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 &  PlotNCDF = false,
const bool &  ExpBucket = false 
)
static

Definition at line 306 of file gnuplot.h.

308  {
309  TFltPrV IdCntV(ValCntH.Len(), 0), BucketV;
310  for (int i = ValCntH.FFirstKeyId(); ValCntH.FNextKeyId(i); ) {
311  IdCntV.Add(TFltPr(double(ValCntH.GetKey(i)), double(ValCntH[i]))); }
312  IdCntV.Sort();
313  if (ExpBucket) {
314  TGnuPlot::MakeExpBins(IdCntV, BucketV);
315  BucketV.Swap(IdCntV);
316  }
317  if (PlotNCDF) {
318  TFltPrV NCdfV = IdCntV;
319  for (int i = NCdfV.Len()-2; i >= 0; i--) {
320  NCdfV[i].Val2 = NCdfV[i].Val2 + NCdfV[i+1].Val2;
321  }
322  PlotValV(NCdfV, OutFNmPref, Desc, "NCDF "+XLabel, "NCDF "+YLabel, ScaleTy, PowerFit, SeriesTy);
323  } else {
324  PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
325  }
326 }
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:610
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int FFirstKeyId() const
Definition: hash.h:232
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
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)
Definition: gnuplot.h:363
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int Len() const
Definition: hash.h:186
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
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 329 of file gnuplot.h.

332  {
333  PlotValCntH(ValCntH1, Label1, ValCntH2, Label2, THash<TKey, TVal, THashFunc>(), "", OutFNmPref, Desc, XLabel, YLabel,
334  ScaleTy, SeriesTy);
335 }
static void PlotValCntH(const THash< TKey, TVal, THashFunc > &ValCntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const bool &PlotNCDF=false, const bool &ExpBucket=false)
Definition: gnuplot.h:306
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
Definition: hash.h:88
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 338 of file gnuplot.h.

342  {
343  TFltPrV IdCntV1(ValCntH1.Len(), 0), IdCntV2(ValCntH2.Len(), 0), IdCntV3(ValCntH3.Len(), 0);
344  for (int i = ValCntH1.FFirstKeyId(); ValCntH1.FNextKeyId(i); ) {
345  IdCntV1.Add(TFltPr(double(ValCntH1.GetKey(i)), double(ValCntH1[i]))); }
346  for (int i = ValCntH2.FFirstKeyId(); ValCntH2.FNextKeyId(i); ) {
347  IdCntV2.Add(TFltPr(double(ValCntH2.GetKey(i)), double(ValCntH2[i]))); }
348  for (int i = ValCntH3.FFirstKeyId(); ValCntH3.FNextKeyId(i); ) {
349  IdCntV3.Add(TFltPr(double(ValCntH3.GetKey(i)), double(ValCntH3[i]))); }
350  IdCntV1.Sort();
351  IdCntV2.Sort();
352  IdCntV3.Sort();
353  TGnuPlot GP(OutFNmPref, Desc);
354  GP.SetXYLabel(XLabel, YLabel);
355  GP.SetScale(ScaleTy);
356  if (! IdCntV1.Empty()) { GP.AddPlot(IdCntV1, SeriesTy, Label1); }
357  if (! IdCntV2.Empty()) { GP.AddPlot(IdCntV2, SeriesTy, Label2); }
358  if (! IdCntV3.Empty()) { GP.AddPlot(IdCntV3, SeriesTy, Label3); }
359  GP.SavePng();
360 }
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int FFirstKeyId() const
Definition: hash.h:232
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:559
int Len() const
Definition: hash.h:186
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:210
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 468 of file gnuplot.h.

470  {
471  TFltTrV AvgV, StdErrV;
472  TFltPrV AvgV2, MedV, MinV, MaxV;
473  TFltPrV ScatterV;
474  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
475  TMom Mom(ValMomH[i]);
476  if (! Mom.IsDef()) { Mom.Def(); }
477  const double x = ValMomH.GetKey(i);
478  if (PlotAvg) {
479  if (PlotSDev) {
480  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
481  else {
482  AvgV2.Add(TFltPr(x, Mom.GetMean()));
483  }
484  if (PlotStdErr) {
485  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
486  }
487  }
488  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
489  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
490  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
491  if (PlotScatter) {
492  THashSet<TFlt> PointSet;
493  for (int xi = 0; xi < ValMomH[i].GetVals(); xi++) {
494  PointSet.AddKey(ValMomH[i].GetVal(xi)); }
495  //ScatterV.Add(TFltPr(x, ValMomH[i].GetVal(xi))); }
496  for (int xi = 0; xi < PointSet.Len(); xi++) {
497  ScatterV.Add(TFltPr(x, PointSet[xi])); }
498  //printf("S%d %d %d.", ValMomH[i].GetVals(), PointSet.Len(), ScatterV.Len());
499  }
500  }
501  AvgV.Sort(); AvgV2.Sort();
502  MedV.Sort(); MinV.Sort(); MaxV.Sort(); StdErrV.Sort();
503  TGnuPlot GP(OutFNmPref, Desc);
504  GP.SetScale(ScaleTy);
505  GP.SetXYLabel(XLabel, YLabel);
506  if (! ScatterV.Empty()) { GP.AddPlot(ScatterV, gpwPoints, "Scatter"); }
507  if (! AvgV.Empty()) { GP.AddErrBar(AvgV, "Average", "StdDev"); }
508  if (! AvgV2.Empty()) { GP.AddPlot(AvgV2, SeriesTy, "Average"); }
509  if (! MedV.Empty()) { GP.AddPlot(MedV, SeriesTy, "Median"); }
510  if (! MinV.Empty()) { GP.AddPlot(MinV, SeriesTy, "Min"); }
511  if (! MaxV.Empty()) { GP.AddPlot(MaxV, SeriesTy, "Max"); }
512  if (! StdErrV.Empty()) { GP.AddErrBar(StdErrV, "Standard error"); }
513  GP.SavePng();
514 }
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1218
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int AddKey(const TKey &Key)
Definition: shash.h:1254
int FFirstKeyId() const
Definition: hash.h:232
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:175
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:559
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:420
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 517 of file gnuplot.h.

519  {
520  TFltTrV AvgV1, AvgV2, StdErrV1, StdErrV2;
521  TFltPrV AvgVM1, MedV1, MinV1, MaxV1;
522  TFltPrV AvgVM2, MedV2, MinV2, MaxV2;
523  TFltPrV ScatterV1, ScatterV2;
524  // ValMom1
525  for (int i = ValMomH1.FFirstKeyId(); ValMomH1.FNextKeyId(i); ) {
526  TMom Mom(ValMomH1[i]);
527  if (! Mom.IsDef()) { Mom.Def(); }
528  const double x = ValMomH1.GetKey(i);
529  if (PlotAvg) {
530  if (PlotSDev) {
531  AvgV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
532  else {
533  AvgVM1.Add(TFltPr(x, Mom.GetMean()));
534  }
535  if (PlotStdErr) {
536  StdErrV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
537  }
538  }
539  if (PlotMed) { MedV1.Add(TFltPr(x, Mom.GetMedian())); }
540  if (PlotMin) { MinV1.Add(TFltPr(x, Mom.GetMn())); }
541  if (PlotMax) { MaxV1.Add(TFltPr(x, Mom.GetMx())); }
542  if (PlotScatter) {
543  THashSet<TFlt> PointSet;
544  for (int xi = 0; xi < ValMomH1[i].GetVals(); xi++) {
545  PointSet.AddKey(ValMomH1[i].GetVal(xi)); }
546  for (int xi = 0; xi < PointSet.Len(); xi++) {
547  ScatterV1.Add(TFltPr(x, PointSet[xi])); }
548  }
549  }
550  AvgV1.Sort(); AvgVM1.Sort(); MedV1.Sort(); MinV1.Sort(); MaxV1.Sort(); StdErrV1.Sort();
551  // ValMom2
552  for (int i = ValMomH2.FFirstKeyId(); ValMomH2.FNextKeyId(i); ) {
553  TMom Mom(ValMomH2[i]);
554  if (! Mom.IsDef()) { Mom.Def(); }
555  const double x = ValMomH2.GetKey(i);
556  if (PlotAvg) {
557  if (PlotSDev) {
558  AvgV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
559  else {
560  AvgVM2.Add(TFltPr(x, Mom.GetMean()));
561  }
562  if (PlotStdErr) {
563  StdErrV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
564  }
565  }
566  if (PlotMed) { MedV2.Add(TFltPr(x, Mom.GetMedian())); }
567  if (PlotMin) { MinV2.Add(TFltPr(x, Mom.GetMn())); }
568  if (PlotMax) { MaxV2.Add(TFltPr(x, Mom.GetMx())); }
569  if (PlotScatter) {
570  THashSet<TFlt> PointSet;
571  for (int xi = 0; xi < ValMomH2[i].GetVals(); xi++) {
572  PointSet.AddKey(ValMomH2[i].GetVal(xi)); }
573  for (int xi = 0; xi < PointSet.Len(); xi++) {
574  ScatterV2.Add(TFltPr(x, PointSet[xi])); }
575  }
576  }
577  AvgV2.Sort(); AvgVM2.Sort(); MedV2.Sort(); MinV2.Sort(); MaxV2.Sort(); StdErrV2.Sort();
578  // plot
579  TGnuPlot GP(OutFNmPref, Desc);
580  GP.SetScale(ScaleTy);
581  GP.SetXYLabel(XLabel, YLabel);
582  // ValMom1
583  if (! ScatterV1.Empty()) { GP.AddPlot(ScatterV1, gpwPoints, Label1+": Scatter"); }
584  if (! AvgV1.Empty()) { GP.AddErrBar(AvgV1, Label1+": Average", Label1+": StdDev"); }
585  if (! AvgVM1.Empty()) { GP.AddPlot(AvgVM1, SeriesTy, Label1+": Average"); }
586  if (! MedV1.Empty()) { GP.AddPlot(MedV1, SeriesTy, Label1+": Median"); }
587  if (! MinV1.Empty()) { GP.AddPlot(MinV1, SeriesTy, Label1+": Min"); }
588  if (! MaxV1.Empty()) { GP.AddPlot(MaxV1, SeriesTy, Label1+": Max"); }
589  if (! StdErrV1.Empty()) { GP.AddErrBar(StdErrV1, Label1+": Std error"); }
590  // ValMom2
591  if (! ScatterV2.Empty()) { GP.AddPlot(ScatterV2, gpwPoints, Label2+": Scatter"); }
592  if (! AvgV2.Empty()) { GP.AddErrBar(AvgV2, Label2+": Average", Label2+": StdDev"); }
593  if (! AvgVM2.Empty()) { GP.AddPlot(AvgVM2, SeriesTy, Label2+": Average"); }
594  if (! MedV2.Empty()) { GP.AddPlot(MedV2, SeriesTy, Label2+": Median"); }
595  if (! MinV2.Empty()) { GP.AddPlot(MinV2, SeriesTy, Label2+": Min"); }
596  if (! MaxV2.Empty()) { GP.AddPlot(MaxV2, SeriesTy, Label2+": Max"); }
597  if (! StdErrV2.Empty()) { GP.AddErrBar(StdErrV2, Label2+": Std error"); }
598  GP.SavePng();
599 }
Definition: xmath.h:129
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:530
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1218
bool FNextKeyId(int &KeyId) const
Definition: hash.h:432
int AddKey(const TKey &Key)
Definition: shash.h:1254
int FFirstKeyId() const
Definition: hash.h:232
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:175
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:559
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:420
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 363 of file gnuplot.h.

364  {
365  TFltKdV IdCntV(ValV.Len(), 0);
366  for (int i = 0; i < ValV.Len(); i++) {
367  IdCntV.Add(TFltKd(double(ValV[i].Val1), double(ValV[i].Val2))); }
368  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
369  IdCntV.Sort();
370  TGnuPlot GP(OutFNmPref, Desc);
371  GP.SetXYLabel(XLabel, YLabel);
372  GP.SetScale(ScaleTy);
373  const int Id = GP.AddPlot(IdCntV, SeriesTy);
374  if (PowerFit) {
375  GP.AddPwrFit3(Id);
376  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
377  if (MaxY < MinY) { Swap(MaxY, MinY); }
378  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
379  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
380  }
381  GP.SavePng();
382 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
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:559
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 385 of file gnuplot.h.

386  {
387  TFltKdV IdCntV(ValV.Len(), 0);
388  TFltV DeltaYV(ValV.Len(), 0);
389  for (int i = 0; i < ValV.Len(); i++) {
390  IdCntV.Add(TFltKd(double(ValV[i].Val1), double(ValV[i].Val2)));
391  DeltaYV.Add(double(ValV[i].Val3));
392  }
393  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
394  IdCntV.Sort();
395  TGnuPlot GP(OutFNmPref, Desc);
396  GP.SetXYLabel(XLabel, YLabel);
397  GP.SetScale(ScaleTy);
398  const int Id = GP.AddPlot(IdCntV, SeriesTy);
399  GP.AddErrBar(IdCntV, DeltaYV, ErrBarStr);
400  if (PowerFit) {
401  GP.AddPwrFit3(Id);
402  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
403  if (MaxY < MinY) { Swap(MaxY, MinY); }
404  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
405  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
406  }
407  GP.SavePng();
408 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
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:559
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 412 of file gnuplot.h.

414  {
415  TFltKdV IdCntV1(ValV1.Len(), 0), IdCntV2(ValV2.Len(), 0);
416  for (int i = 0; i < ValV1.Len(); i++) {
417  IdCntV1.Add(TFltKd(double(ValV1[i].Val1), double(ValV1[i].Val2))); }
418  for (int i = 0; i < ValV2.Len(); i++) {
419  IdCntV2.Add(TFltKd(double(ValV2[i].Val1), double(ValV2[i].Val2))); }
420  if (IdCntV1.Empty() || IdCntV2.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
421  IdCntV1.Sort();
422  IdCntV2.Sort();
423  TGnuPlot GP(OutFNmPref, Desc);
424  GP.SetXYLabel(XLabel, YLabel);
425  GP.SetScale(ScaleTy);
426  { const int Id = GP.AddPlot(IdCntV1, SeriesTy, Name1);
427  if (PowerFit) {
428  GP.AddPwrFit3(Id);
429  double MaxY = IdCntV1.Last().Dat, MinY = IdCntV1[0].Dat;
430  if (MaxY < MinY) { Swap(MaxY, MinY); }
431  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
432  } }
433  { const int Id = GP.AddPlot(IdCntV2, SeriesTy, Name2);
434  if (PowerFit) {
435  GP.AddPwrFit3(Id);
436  double MaxY = IdCntV2.Last().Dat, MinY = IdCntV2[0].Dat;
437  if (MaxY < MinY) { Swap(MaxY, MinY); }
438  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
439  } }
440  GP.SavePng();
441 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
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:559
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
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 446 of file gnuplot.h.

447  {
448  TFltKdV IdCntV(ValV.Len(), 0);
449  for (int i = 0; i < ValV.Len(); i++) {
450  IdCntV.Add(TFltKd(double(i+1), double(ValV[i]))); }
451  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
452  IdCntV.Sort();
453  TGnuPlot GP(OutFNmPref, Desc);
454  GP.SetXYLabel(XLabel, YLabel);
455  GP.SetScale(ScaleTy);
456  const int Id = GP.AddPlot(IdCntV, SeriesTy);
457  if (PowerFit) {
458  GP.AddPwrFit3(Id);
459  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
460  if (MaxY < MinY) { Swap(MaxY, MinY); }
461  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
462  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
463  }
464  GP.SavePng();
465 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:386
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:559
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568
void TGnuPlot::RunGnuPlot ( ) const

Definition at line 869 of file gnuplot.cpp.

869  {
870  // try running gnuplot
871  if (system(TStr::Fmt("%s %s", GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
872  if (! GnuPlotPath.Empty()) {
873  #if defined(GLib_WIN)
874  if (system(TStr::Fmt("%s\\%s %s", GnuPlotPath.CStr(), GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
875  #else
876  if (system(TStr::Fmt("%s/%s %s", GnuPlotPath.CStr(), GnuPlotFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
877  #endif
878  }
879  //Old
880  //#if defined(GLib_WIN)
881  //if (system(TStr::Fmt(".\\%s %s", GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
882  //#else
883  //if (system(TStr::Fmt("./%s %s", GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
884  //#endif
885  //if (system(TStr::Fmt("%s%s %s", GpPath.CStr(), GpFNm.CStr(), PlotFNm.CStr()).CStr())==0) { return; }
886  //FailR(TStr::Fmt("Cannot find GnuPlot (%s) for plot %s. Set the PATH.", GpFNm.CStr(), PlotFNm.CStr()).CStr());
887  //ErrNotify(TStr::Fmt("Cannot find GnuPlot (%s) for plot %s. Set the PATH.", GpFNm.CStr(), PlotFNm.CStr()).CStr());
888  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());
889 }
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 600 of file gnuplot.cpp.

600  {
601  AddCmd(TStr::Fmt("set terminal postscript enhanced eps %d color", FontSz));
602  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
603  Pause(false);
604  CreatePlotFile(Comment.Empty()? Title : Comment);
605  RunGnuPlot();
606  MoreCmds.DelLast();
607  MoreCmds.DelLast();
608 }
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:869
void DelLast()
Removes the last element of the vector.
Definition: ds.h:609
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:764
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 578 of file gnuplot.cpp.

578  {
579  if (Terminal.Empty()) {
580  //#ifdef GLib_WIN
581  //#ifndef GLib_MACOSX // The standard GNUPlot for MacOS does not support PNG (Jure: actually version 4.6 DOES!)
582  // RS 2014/06/17 standard GNUPlot is tricky to configure for PNG on MacOS
583  AddCmd(TStr::Fmt("set terminal png size %d,%d", SizeX, SizeY));
584  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
585  //#else // EPS
586  //AddCmd("set terminal postscript eps 10 enhanced color");
587  //AddCmd(TStr::Fmt("set output '%s%s.eps'", FNm.GetFPath().CStr(), FNm.GetFMid().CStr()));
588  //#endif
589  } else {
590  AddCmd(Terminal);
591  AddCmd(TStr::Fmt("set output '%s'", FNm.CStr()));
592  }
593  Pause(false);
594  CreatePlotFile(Comment.Empty()? Title : Comment);
595  RunGnuPlot();
596  MoreCmds.DelLast();
597  MoreCmds.DelLast();
598 }
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:869
void DelLast()
Removes the last element of the vector.
Definition: ds.h:609
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:764
TStrV MoreCmds
Definition: gnuplot.h:56
void TGnuPlot::SaveTs ( const TIntKdV KdV,
const TStr FNm,
const TStr HeadLn = TStr() 
)
static

Definition at line 713 of file gnuplot.cpp.

713  {
714  FILE *F = fopen(FNm.CStr(), "wt");
715  EAssert(F);
716  if (! HeadLn.Empty()) fprintf(F, "# %s\n", HeadLn.CStr());
717  for (int i = 0; i < KdV.Len(); i++) {
718  fprintf(F, "%d\t%d\n", KdV[i].Key(), KdV[i].Dat()); }
719  fclose(F);
720 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#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 723 of file gnuplot.cpp.

723  {
724  FILE *F = fopen(FNm.CStr(), "wt");
725  EAssert(F);
726  if (! HeadLn.Empty()) fprintf(F, "# %s\n", HeadLn.CStr());
727  for (int i = 0; i < KdV.Len(); i++)
728  fprintf(F, "%d\t%g\n", KdV[i].Key(), KdV[i].Dat());
729  fclose(F);
730 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#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 215 of file gnuplot.h.

215  {
216  FILE *F = fopen(FNm.CStr(), "wt");
217  EAssert(F);
218  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
219  for (int i = 0; i < ValV.Len(); i++) {
220  fprintf(F, "%g\t%g\n", double(ValV[i].Val1), double(ValV[i].Val2)); }
221  fclose(F);
222 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#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 225 of file gnuplot.h.

225  {
226  FILE *F = fopen(FNm.CStr(), "wt");
227  EAssert(F);
228  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
229  for (int i = 0; i < ValV.Len(); i++) {
230  fprintf(F, "%g\t%g\t%g\n", double(ValV[i].Val1), double(ValV[i].Val2), double(ValV[i].Val3)); }
231  fclose(F);
232 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#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 235 of file gnuplot.h.

235  {
236  FILE *F = fopen(FNm.CStr(), "wt");
237  EAssert(F);
238  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
239  for (int i = 0; i < ValV.Len(); i++) {
240  fprintf(F, "%g", double(ValV[i][0]));
241  for (int v = 1; v < Vals; v++) {
242  fprintf(F, "\t%g", double(ValV[i][v])); }
243  fprintf(F, "\n");
244  }
245  fclose(F);
246 }
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
#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 732 of file gnuplot.cpp.

732  {
733  TFltV DeltaY;
734  TFltPrV ValV1, ValV2, ValV3;
735  for (int i = 1; i < 30; i++) {
736  ValV1.Add(TFltPr(i, pow(double(i), 1.2)));
737  DeltaY.Add(5*TInt::Rnd.GetUniDev());
738  ValV2.Add(TFltPr(i, 5*i-1));
739  }
740  for (int i = -10; i < 20; i++) {
741  ValV3.Add(TFltPr(i, 2*i + 2 + TInt::Rnd.GetUniDev()));
742  }
743  TGnuPlot GnuPlot("testDat", "TestPlot", true);
744  GnuPlot.SetXYLabel("X", "Y");
745  const int id2 = GnuPlot.AddPlot(ValV2, gpwPoints, "y=5*x-1");
746  const int id3 = GnuPlot.AddPlot(ValV3, gpwPoints, "y=2*x+2");
747  GnuPlot.AddErrBar(ValV1, DeltaY, "y=x^2", "Error bar");
748  GnuPlot.AddLinFit(id2, gpwLines);
749  GnuPlot.AddLinFit(id3, gpwLines);
750  GnuPlot.Plot();
751  GnuPlot.SavePng("testPlot.png");
752 }
static TRnd Rnd
Definition: dt.h:1051
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:559

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: