SNAP Library 6.0, User Reference  2020-12-09 16:24:20
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
gnuplot.h
Go to the documentation of this file.
1 #ifndef gnuplot_h
2 #define gnuplot_h
3 
5 // GNU-Plot-Chart
6 typedef enum {
9 } TGpScaleTy;
10 
11 typedef enum {
14 } TGpSeriesTy;
15 
16 class TGnuPlot {
17 public:
19  static TStr GnuPlotPath;
21  static TStr GnuPlotFNm;
22  static TStr DefPlotFNm;
23  static TStr DefDataFNm;
24 private:
25  class TGpSeries {
26  public:
29  TFltV ZValV; // error bar and 3d plots
31  int XCol, YCol, ZCol;
32  public:
33  TGpSeries() : SeriesTy(gpwLines), XYValV(), ZValV(), Label(), WithStyle(), DataFNm(), XCol(0), YCol(0), ZCol(0) { }
34  TGpSeries(const TGpSeries& Gps);
35  TGpSeries& operator = (const TGpSeries& Gps);
36  bool operator < (const TGpSeries& Gps) const;
37  bool SaveXVals() const { return (YCol-XCol)==1; }
38  };
39  class TGpSeriesCmp {
40  private:
42  public:
43  TGpSeriesCmp(const TVec<TGpSeries>& _SeriesV) : SeriesV(_SeriesV) { }
44  bool operator () (const int& Left, const int& Right) const {
45  return SeriesV[Left] > SeriesV[Right]; }
46  };
47 private:
48  static int Tics42; // 1 - "set ticks", 0 - "set ticscale"
49  // -1 - unknown, -2 - not initialized
57 public:
58  static int GetTics42();
59 public:
60  TStr GetSeriesPlotStr(const int& PlotN);
61  int IsSameXCol(const int& CurId, const int& PrevId) const;
62  void CreatePlotFile(const TStr& Comment = TStr());
63  void RunGnuPlot() const;
64 public:
65  TGnuPlot(const TStr& FileNm="gplot", const TStr& PlotTitle=TStr(), const bool& Grid=true);
66  TGnuPlot(const TStr& DataFileNm, const TStr& PlotFileNm, const TStr& PlotTitle, const bool& Grid);
67  TGnuPlot(const TGnuPlot& GnuPlot);
68  TGnuPlot& operator = (const TGnuPlot& GnuPlot);
69 
70  void SetTitle(const TStr& PlotTitle) { Title = PlotTitle; }
71  void SetXLabel(const TStr& XLabel) { LblX = XLabel; }
72  void SetYLabel(const TStr& YLabel) { LblY = YLabel; }
73  void SetXYLabel(const TStr& XLabel, const TStr& YLabel) { LblX = XLabel; LblY = YLabel; }
74  void SetDataPlotFNm(const TStr& DatFNm, const TStr& PltFNm) { DataFNm = DatFNm; PlotFNm = PltFNm; }
75 
76  void ShowGrid(const bool& Show) { SetGrid = Show; }
77  void Pause(const bool& DoPause) { SetPause = DoPause; }
78  void SetScale(const TGpScaleTy& GpScaleTy) { ScaleTy = GpScaleTy;}
79  void SetXRange(const double& Min, const double& Max) { XRange = TFltPr(Min, Max); }
80  void SetYRange(const double& Min, const double& Max) { YRange = TFltPr(Min, Max); }
81  void AddCmd(const TStr& Cmd) { MoreCmds.Add(Cmd); }
82  TStr GetLineStyle(const int& PlotId) const { return SeriesV[PlotId].WithStyle; }
83  void SetLineStyle(const int& PlotId, const TStr& StyleStr) { SeriesV[PlotId].WithStyle = StyleStr; }
84 
85  int AddFunc(const TStr& FuncStr, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
86  int AddPlot(const TIntV& YValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
87  int AddPlot(const TFltV& YValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
88  int AddPlot(const TFltV& XValV, const TFltV& YValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
89  int AddPlot(const TIntPrV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
90  int AddPlot(const TFltPrV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
91  int AddPlot(const TIntKdV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
92  int AddPlot(const TFltKdV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
93  int AddPlot(const TIntFltKdV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
94  int AddPlot(const TIntFltPrV& XYValV, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
95  int AddPlot(const TStr& DataFNm, const int& ColY, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
96  int AddPlot(const TStr& DataFNm, const int& ColX, const int& ColY, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr());
97  template<class TKey, class TDat, class THashFunc>
98  int AddPlot(const THash<TKey, TDat, THashFunc>& XYValH, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr(), const bool& ExpBucket = false);
99  template<class TKey, class THashFunc>
100  int AddPlot(const THash<TKey, TMom, THashFunc>& ValMomH, const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& Label=TStr(), const TStr& Style=TStr(),
101  bool PlotAvg=true, bool PlotMed=true, bool PlotMin=false, bool PlotMax=false, bool PlotSDev=false, bool PlotStdErr=false, const bool& ExpBucket=false);
102 
103  int AddErrBar(const TFltTrV& XYDValV, const TStr& Label=TStr());
104  int AddErrBar(const TFltTrV& XYDValV, const TStr& DatLabel, const TStr& ErrLabel);
105  int AddErrBar(const TFltV& YValV, const TFltV& DeltaYV, const TStr& Label=TStr());
106  int AddErrBar(const TFltV& XValV, const TFltV& YValV, const TFltV& DeltaYV, const TStr& Label=TStr());
107  int AddErrBar(const TFltPrV& XYValV, const TFltV& DeltaYV, const TStr& Label=TStr());
108  int AddErrBar(const TFltKdV& XYValV, const TFltV& DeltaYV, const TStr& Label=TStr());
109  int AddErrBar(const TFltPrV& XYValV, const TFltV& DeltaYV, const TStr& DatLabel, const TStr& ErrLabel);
110 
111  int AddLinFit(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const TStr& Style=TStr());
112  int AddPwrFit(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const TStr& Style=TStr());
113  int AddPwrFit1(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const TStr& Style=TStr());
114  int AddPwrFit2(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const double& MinX=-1.0, const TStr& Style=TStr());
115  int AddPwrFit3(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const double& MinX=-1.0, const TStr& Style=TStr());
116  int AddPwrFit3(const int& PlotId, const TGpSeriesTy& SeriesTy, const double& MinX, const TStr& Style, double& Intercept, double& Slope, double& R2);
117  int AddLogFit(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const TStr& Style=TStr());
118  int AddExpFit(const int& PlotId, const TGpSeriesTy& SeriesTy=gpwLines, const double& FitXOffset=0.0, const TStr& Style=TStr());
119 
120  void SavePng(const int& SizeX=1000, const int& SizeY=800, const TStr& Comment=TStr()) {
121  SavePng(PlotFNm.GetFPath()+PlotFNm.GetFMid()+".png", SizeX, SizeY, Comment); }
122  void SavePng(const TStr& FNm, const int& SizeX=1000, const int& SizeY=800, const TStr& Comment=TStr(), const TStr& Terminal=TStr());
123  void SaveEps(const int& FontSz=30, const TStr& Comment=TStr()) {
124  SaveEps(PlotFNm.GetFPath()+PlotFNm.GetFMid()+".eps", FontSz, Comment); }
125  void SaveEps(const TStr& FNm, const int& FontSz=30, const TStr& Comment=TStr());
126  void Plot(const TStr& Comment=TStr()) { CreatePlotFile(Comment); RunGnuPlot(); }
127 
128  static void MakeExpBins(const TFltPrV& XYValV, TFltPrV& ExpXYValV,
129  const double& BinFactor = 2, const double& MinYVal = 1);
130  static void MakeExpBins(const TFltKdV& XYValV, TFltKdV& ExpXYValV,
131  const double& BinFactor = 2, const double& MinYVal = 1);
132  static void LoadTs(const TStr& FNm, TStrV& ColNmV, TVec<TFltKdV>& ColV);
133 
134  static TStr GetScaleStr(const TGpScaleTy& ScaleTy);
135  static TStr GetSeriesTyStr(const TGpSeriesTy& SeriesTy);
136 
137  // save tab separated
138  static void SaveTs(const TIntKdV& KdV, const TStr& FNm, const TStr& HeadLn = TStr());
139  static void SaveTs(const TIntFltKdV& KdV, const TStr& FNm, const TStr& HeadLn = TStr());
140  template <class TVal1, class TVal2>
141  static void SaveTs(const TVec<TPair<TVal1, TVal2> >& ValV, const TStr& FNm, const TStr& HeadLn = TStr());
142  template <class TVal1, class TVal2, class TVal3>
143  static void SaveTs(const TVec<TTriple<TVal1, TVal2, TVal3> >& ValV, const TStr& FNm, const TStr& HeadLn = TStr());
144  template <class TVal, int Vals>
145  static void SaveTs(const TVec<TTuple<TVal, Vals> >& ValV, const TStr& FNm, const TStr& HeadLn = TStr());
146  static void Test();
147 
148  // plot value-count tables, and pair vectors
149  template <class TVal1>
150  static void PlotValV(const TVec<TVal1>& ValV, const TStr& OutFNmPref, const TStr& Desc="",
151  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
152  const TGpSeriesTy& SeriesTy=gpwLinesPoints);
153  template <class TVal1, class TVal2>
154  static void PlotValV(const TVec<TPair<TVal1, TVal2> >& ValV, const TStr& OutFNmPref, const TStr& Desc="",
155  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
156  const TGpSeriesTy& SeriesTy=gpwLinesPoints);
157  template <class TVal1, class TVal2, class TVal3>
158  static void PlotValV(const TVec<TTriple<TVal1, TVal2, TVal3> >& ValV, const TStr& OutFNmPref, const TStr& Desc="",
159  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
160  const TGpSeriesTy& SeriesTy=gpwLinesPoints, const TStr& ErrBarStr = "");
161  template <class TVal1, class TVal2>
162  static void PlotValV(const TVec<TPair<TVal1, TVal2> >& ValV1, const TStr& Name1,
163  const TVec<TPair<TVal1, TVal2> >& ValV2, const TStr& Name2, const TStr& OutFNmPref, const TStr& Desc="",
164  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
165  const TGpSeriesTy& SeriesTy=gpwLinesPoints);
166  template <class TKey, class TVal, class THashFunc>
167  static void PlotValRank(const THash<TKey, TVal, THashFunc>& ValCntH, const TStr& OutFNmPref, const TStr& Desc="",
168  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
169  const TGpSeriesTy& SeriesTy=gpwLinesPoints);
170  template <class TKey, class TVal, class THashFunc>
171  static void PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH, const TStr& OutFNmPref, const TStr& Desc="",
172  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const bool& PowerFit=false,
173  const TGpSeriesTy& SeriesTy=gpwLinesPoints, const bool& PlotCCDF=false, const bool& ExpBucket=false);
174  template <class TKey, class TVal, class THashFunc>
175  static void PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH1, const TStr& Label1,
176  const THash<TKey, TVal, THashFunc>& ValCntH2, const TStr& Label2,
177  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel, const TStr& YLabel,
178  const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints);
179  template <class TKey, class TVal, class THashFunc>
180  static void PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH1, const TStr& Label1,
181  const THash<TKey, TVal, THashFunc>& ValCntH2, const TStr& Label2,
182  const THash<TKey, TVal, THashFunc>& ValCntH3, const TStr& Label3,
183  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel, const TStr& YLabel,
184  const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints);
185  template <class TVal1>
186  static void PlotValMomH(const THash<TVal1, TMom>& ValMomH, const TStr& OutFNmPref, const TStr& Desc="",
187  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints,
188  bool PlotAvg=true, bool PlotMed=true, bool PlotMin=false, bool PlotMax=false, bool PlotSDev=false, bool PlotStdErr=true, bool PlotScatter=false);
189  template <class TVal1>
190  static void PlotValMomH(const THash<TVal1, TMom>& ValMomH1, const TStr& Label1, const THash<TVal1, TMom>& ValMomH2, const TStr& Label2,
191  const TStr& OutFNmPref, const TStr& Desc="",
192  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints,
193  bool PlotAvg=true, bool PlotMed=true, bool PlotMin=false, bool PlotMax=false, bool PlotSDev=false, bool PlotStdErr=true, bool PlotScatter=false);
194  template <class TVal2>
195  static void PlotValOverTm(const TVec<TPair<TSecTm, TVal2> >& ValV, const TStr& OutFNmPref, const TStr& Desc="",
196  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints);
197  template <class TVal2>
198  static void PlotCntOverTm(const THash<TSecTm, TVal2>& CntH, const TStr& OutFNmPref, const TStr& Desc="",
199  const TStr& XLabel="", const TStr& YLabel="", const TGpScaleTy& ScaleTy=gpsAuto, const TGpSeriesTy& SeriesTy=gpwLinesPoints);
200 
201 };
202 
203 //---------------------------------------------------------
204 // useful commands
205 // set terminal png small size 800,600
206 // set terminal postscript enhanced eps 22
207 // set output 'hopsasa.png'
208 // set size 1,0.5
209 // set pointsize 0.9
210 // set key right bottom Left
211 // set style fill solid 0.2
212 // set ticscale 3 1 # longer axis tics
213 // plot ... with points pointtype 6 pointsize 1
214 // 1 + 7 (f) circle
215 // 2 cross 8 (o) triangle
216 // 3 * 9 (f) triangle
217 // 4 (o) square 10 (o) inverse-triangle
218 // 5 (f) square 11 (f) inverse-triangle
219 // 6 (o) circle 12 (o) diamond
220 // 13 (f) diamond
221 // set label "Text" at 23,47000
222 // set arrow from 28,45000 to 28,31000 lw 3
223 // axes x1y2: http://t16web.lanl.gov/Kawano/gnuplot/plot1-e.html#5.2
224 
225 template <class TVal1, class TVal2>
226 void TGnuPlot::SaveTs(const TVec<TPair<TVal1, TVal2> >& ValV, const TStr& FNm, const TStr& HeadLn) {
227  FILE *F = fopen(FNm.CStr(), "wt");
228  EAssert(F);
229  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
230  for (int i = 0; i < ValV.Len(); i++) {
231  fprintf(F, "%g\t%g\n", double(ValV[i].Val1), double(ValV[i].Val2)); }
232  fclose(F);
233 }
234 
235 template <class TVal1, class TVal2, class TVal3>
236 void TGnuPlot::SaveTs(const TVec<TTriple<TVal1, TVal2, TVal3> >& ValV, const TStr& FNm, const TStr& HeadLn) {
237  FILE *F = fopen(FNm.CStr(), "wt");
238  EAssert(F);
239  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
240  for (int i = 0; i < ValV.Len(); i++) {
241  fprintf(F, "%g\t%g\t%g\n", double(ValV[i].Val1), double(ValV[i].Val2), double(ValV[i].Val3)); }
242  fclose(F);
243 }
244 
245 template <class TVal, int Vals>
246 void TGnuPlot::SaveTs(const TVec<TTuple<TVal, Vals> >& ValV, const TStr& FNm, const TStr& HeadLn) {
247  FILE *F = fopen(FNm.CStr(), "wt");
248  EAssert(F);
249  if (! HeadLn.Empty()) { fprintf(F, "# %s\n", HeadLn.CStr()); }
250  for (int i = 0; i < ValV.Len(); i++) {
251  fprintf(F, "%g", double(ValV[i][0]));
252  for (int v = 1; v < Vals; v++) {
253  fprintf(F, "\t%g", double(ValV[i][v])); }
254  fprintf(F, "\n");
255  }
256  fclose(F);
257 }
258 
259 template<class TKey, class TDat, class THashFunc>
260 int TGnuPlot::AddPlot(const THash<TKey, TDat, THashFunc>& XYValH, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style, const bool& ExpBucket) {
261  TFltPrV XYFltValV(XYValH.Len(), 0);
262  for (int k = XYValH.FFirstKeyId(); XYValH.FNextKeyId(k); ) {
263  XYFltValV.Add(TFltPr(TFlt(XYValH.GetKey(k)), TFlt(XYValH[k])));
264  }
265  XYFltValV.Sort();
266  if (ExpBucket) {
267  TFltPrV BucketV;
268  TGnuPlot::MakeExpBins(XYFltValV, BucketV);
269  BucketV.Swap(XYFltValV);
270  }
271  return AddPlot(XYFltValV, SeriesTy, Label, Style);
272 }
273 
274 template<class TKey, class THashFunc>
275 int TGnuPlot::AddPlot(const THash<TKey, TMom, THashFunc>& ValMomH, const TGpSeriesTy& SeriesTy, const TStr& Label, const TStr& Style, bool PlotAvg, bool PlotMed, bool PlotMin, bool PlotMax, bool PlotSDev, bool PlotStdErr, const bool& ExpBucket) {
276  TFltTrV AvgV, StdErrV;
277  TFltPrV AvgV2, MedV, MinV, MaxV, BucketV;
278  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
279  TMom Mom(ValMomH[i]);
280  if (! Mom.IsDef()) { Mom.Def(); }
281  const double x = ValMomH.GetKey(i);
282  if (PlotAvg) {
283  if (PlotSDev) {
284  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
285  else if (PlotStdErr) {
286  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
287  } else {
288  AvgV2.Add(TFltPr(x, Mom.GetMean()));
289  }
290  }
291  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
292  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
293  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
294  }
295  AvgV.Sort(); AvgV2.Sort();
296  MedV.Sort(); MinV.Sort(); MaxV.Sort();
297  int PlotId=0;
298  // exponential bucketing
299  if (ExpBucket) {
300  if (! AvgV2.Empty()) { TGnuPlot::MakeExpBins(AvgV2, BucketV); BucketV.Swap(AvgV2); }
301  if (! MedV.Empty()) { TGnuPlot::MakeExpBins(MedV, BucketV); BucketV.Swap(MedV); }
302  if (! MinV.Empty()) { TGnuPlot::MakeExpBins(MinV, BucketV); BucketV.Swap(MinV); }
303  if (! MaxV.Empty()) { TGnuPlot::MakeExpBins(MaxV, BucketV); BucketV.Swap(MaxV); }
304  }
305  // plot
306  if (! AvgV.Empty()) { PlotId = AddErrBar(AvgV, Label+" Average", Label+" StdDev"); }
307  if (! AvgV2.Empty()) { PlotId = AddPlot(AvgV2, SeriesTy, Label+" Average", Style); }
308  if (! MedV.Empty()) { PlotId = AddPlot(MedV, SeriesTy, Label+" Median", Style); }
309  if (! MinV.Empty()) { PlotId = AddPlot(MinV, SeriesTy, Label+" Min", Style); }
310  if (! MaxV.Empty()) { PlotId = AddPlot(MaxV, SeriesTy, Label+" Max", Style); }
311  if (! StdErrV.Empty()) { PlotId = AddErrBar(StdErrV, Label+" Average", Label+" StdErr"); }
312  return PlotId;
313 }
314 
315 template <class TVal1, class TVal2>
316 void TGnuPlot::PlotValV(const TVec<TPair<TVal1, TVal2> >& ValV, const TStr& OutFNmPref, const TStr& Desc,
317  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const bool& PowerFit, const TGpSeriesTy& SeriesTy) {
318  TFltKdV IdCntV(ValV.Len(), 0);
319  for (int i = 0; i < ValV.Len(); i++) {
320  IdCntV.Add(TFltKd(double(ValV[i].Val1), double(ValV[i].Val2))); }
321  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
322  IdCntV.Sort();
323  TGnuPlot GP(OutFNmPref, Desc);
324  GP.SetXYLabel(XLabel, YLabel);
325  GP.SetScale(ScaleTy);
326  const int Id = GP.AddPlot(IdCntV, SeriesTy);
327  if (PowerFit) {
328  GP.AddPwrFit3(Id);
329  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
330  if (MaxY < MinY) { Swap(MaxY, MinY); }
331  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
332  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
333  }
334  GP.SavePng();
335 }
336 
337 template <class TVal1, class TVal2, class TVal3>
338 void TGnuPlot::PlotValV(const TVec<TTriple<TVal1, TVal2, TVal3> >& ValV, const TStr& OutFNmPref, const TStr& Desc,
339  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const bool& PowerFit,
340  const TGpSeriesTy& SeriesTy, const TStr& ErrBarStr) {
341  TFltKdV IdCntV(ValV.Len(), 0);
342  TFltV DeltaYV(ValV.Len(), 0);
343  for (int i = 0; i < ValV.Len(); i++) {
344  IdCntV.Add(TFltKd(double(ValV[i].Val1), double(ValV[i].Val2)));
345  DeltaYV.Add(double(ValV[i].Val3));
346  }
347  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
348  IdCntV.Sort();
349  TGnuPlot GP(OutFNmPref, Desc);
350  GP.SetXYLabel(XLabel, YLabel);
351  GP.SetScale(ScaleTy);
352  const int Id = GP.AddPlot(IdCntV, SeriesTy);
353  GP.AddErrBar(IdCntV, DeltaYV, ErrBarStr);
354  if (PowerFit) {
355  GP.AddPwrFit3(Id);
356  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
357  if (MaxY < MinY) { Swap(MaxY, MinY); }
358  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
359  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
360  }
361  GP.SavePng();
362 }
363 
364 template <class TVal1, class TVal2>
365 void TGnuPlot::PlotValV(const TVec<TPair<TVal1, TVal2> >& ValV1, const TStr& Name1,
366  const TVec<TPair<TVal1, TVal2> >& ValV2, const TStr& Name2,
367  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel, const TStr& YLabel,
368  const TGpScaleTy& ScaleTy, const bool& PowerFit, const TGpSeriesTy& SeriesTy) {
369  TFltKdV IdCntV1(ValV1.Len(), 0), IdCntV2(ValV2.Len(), 0);
370  for (int i = 0; i < ValV1.Len(); i++) {
371  IdCntV1.Add(TFltKd(double(ValV1[i].Val1), double(ValV1[i].Val2))); }
372  for (int i = 0; i < ValV2.Len(); i++) {
373  IdCntV2.Add(TFltKd(double(ValV2[i].Val1), double(ValV2[i].Val2))); }
374  if (IdCntV1.Empty() || IdCntV2.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
375  IdCntV1.Sort();
376  IdCntV2.Sort();
377  TGnuPlot GP(OutFNmPref, Desc);
378  GP.SetXYLabel(XLabel, YLabel);
379  GP.SetScale(ScaleTy);
380  { const int Id = GP.AddPlot(IdCntV1, SeriesTy, Name1);
381  if (PowerFit) {
382  GP.AddPwrFit3(Id);
383  double MaxY = IdCntV1.Last().Dat, MinY = IdCntV1[0].Dat;
384  if (MaxY < MinY) { Swap(MaxY, MinY); }
385  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
386  } }
387  { const int Id = GP.AddPlot(IdCntV2, SeriesTy, Name2);
388  if (PowerFit) {
389  GP.AddPwrFit3(Id);
390  double MaxY = IdCntV2.Last().Dat, MinY = IdCntV2[0].Dat;
391  if (MaxY < MinY) { Swap(MaxY, MinY); }
392  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
393  } }
394  GP.SavePng();
395 }
396 
397 template <class TVal1>
398 void TGnuPlot::PlotValV(const TVec<TVal1>& ValV, const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel,
399  const TStr& YLabel, const TGpScaleTy& ScaleTy, const bool& PowerFit, const TGpSeriesTy& SeriesTy) {
400  TFltKdV IdCntV(ValV.Len(), 0);
401  for (int i = 0; i < ValV.Len(); i++) {
402  IdCntV.Add(TFltKd(double(i+1), double(ValV[i]))); }
403  if (IdCntV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
404  IdCntV.Sort();
405  TGnuPlot GP(OutFNmPref, Desc);
406  GP.SetXYLabel(XLabel, YLabel);
407  GP.SetScale(ScaleTy);
408  const int Id = GP.AddPlot(IdCntV, SeriesTy);
409  if (PowerFit) {
410  GP.AddPwrFit3(Id);
411  double MaxY = IdCntV.Last().Dat, MinY = IdCntV[0].Dat;
412  if (MaxY < MinY) { Swap(MaxY, MinY); }
413  //GP.SetYRange(MinY, pow(10.0, floor(log10(MaxY))+1.0));
414  GP.AddCmd(TStr::Fmt("set yrange[%f:]", MinY));
415  }
416  GP.SavePng();
417 }
418 
419 template <class TKey, class TVal, class THashFunc>
420 void TGnuPlot::PlotValRank(const THash<TKey, TVal, THashFunc>& ValCntH, const TStr& OutFNmPref, const TStr& Desc,
421  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const bool& PowerFit, const TGpSeriesTy& SeriesTy) {
422  TFltPrV IdCntV(ValCntH.Len(), 0);
423  TFltV ValV(ValCntH.Len(), 0);
424  for (int i = ValCntH.FFirstKeyId(); ValCntH.FNextKeyId(i); ) {
425  ValV.Add(double(ValCntH[i])); }
426  ValV.Sort(false);
427  for (int i = 0; i < ValV.Len(); i++) {
428  IdCntV.Add(TFltPr(i+1, ValV[i]));
429  }
430  PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
431 }
432 
433 template <class TKey, class TVal, class THashFunc>
434 void TGnuPlot::PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH, const TStr& OutFNmPref, const TStr& Desc,
435  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const bool& PowerFit,
436  const TGpSeriesTy& SeriesTy, const bool& PlotCCDF, const bool& ExpBucket) {
437  TFltPrV IdCntV(ValCntH.Len(), 0), BucketV;
438  for (int i = ValCntH.FFirstKeyId(); ValCntH.FNextKeyId(i); ) {
439  IdCntV.Add(TFltPr(double(ValCntH.GetKey(i)), double(ValCntH[i]))); }
440  IdCntV.Sort();
441  if (ExpBucket) {
442  TGnuPlot::MakeExpBins(IdCntV, BucketV);
443  BucketV.Swap(IdCntV);
444  }
445  if (PlotCCDF) {
446  TFltPrV NCdfV = IdCntV;
447  for (int i = NCdfV.Len()-2; i >= 0; i--) {
448  NCdfV[i].Val2 = NCdfV[i].Val2 + NCdfV[i+1].Val2;
449  }
450  PlotValV(NCdfV, OutFNmPref, Desc, "NCDF "+XLabel, "NCDF "+YLabel, ScaleTy, PowerFit, SeriesTy);
451  } else {
452  PlotValV(IdCntV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, PowerFit, SeriesTy);
453  }
454 }
455 
456 template <class TKey, class TVal, class THashFunc>
457 void TGnuPlot::PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH1, const TStr& Label1,
458  const THash<TKey, TVal, THashFunc>& ValCntH2, const TStr& Label2,
459  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel, const TStr& YLabel,
460  const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy) {
461  PlotValCntH(ValCntH1, Label1, ValCntH2, Label2, THash<TKey, TVal, THashFunc>(), "", OutFNmPref, Desc, XLabel, YLabel,
462  ScaleTy, SeriesTy);
463 }
464 
465 template <class TKey, class TVal, class THashFunc>
466 void TGnuPlot::PlotValCntH(const THash<TKey, TVal, THashFunc>& ValCntH1, const TStr& Label1,
467  const THash<TKey, TVal, THashFunc>& ValCntH2, const TStr& Label2,
468  const THash<TKey, TVal, THashFunc>& ValCntH3, const TStr& Label3,
469  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel, const TStr& YLabel,
470  const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy) {
471  TFltPrV IdCntV1(ValCntH1.Len(), 0), IdCntV2(ValCntH2.Len(), 0), IdCntV3(ValCntH3.Len(), 0);
472  for (int i = ValCntH1.FFirstKeyId(); ValCntH1.FNextKeyId(i); ) {
473  IdCntV1.Add(TFltPr(double(ValCntH1.GetKey(i)), double(ValCntH1[i]))); }
474  for (int i = ValCntH2.FFirstKeyId(); ValCntH2.FNextKeyId(i); ) {
475  IdCntV2.Add(TFltPr(double(ValCntH2.GetKey(i)), double(ValCntH2[i]))); }
476  for (int i = ValCntH3.FFirstKeyId(); ValCntH3.FNextKeyId(i); ) {
477  IdCntV3.Add(TFltPr(double(ValCntH3.GetKey(i)), double(ValCntH3[i]))); }
478  IdCntV1.Sort();
479  IdCntV2.Sort();
480  IdCntV3.Sort();
481  TGnuPlot GP(OutFNmPref, Desc);
482  GP.SetXYLabel(XLabel, YLabel);
483  GP.SetScale(ScaleTy);
484  if (! IdCntV1.Empty()) { GP.AddPlot(IdCntV1, SeriesTy, Label1); }
485  if (! IdCntV2.Empty()) { GP.AddPlot(IdCntV2, SeriesTy, Label2); }
486  if (! IdCntV3.Empty()) { GP.AddPlot(IdCntV3, SeriesTy, Label3); }
487  GP.SavePng();
488 }
489 
490 template <class TVal1>
491 void TGnuPlot::PlotValMomH(const THash<TVal1, TMom>& ValMomH, const TStr& OutFNmPref, const TStr& Desc,
492  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy,
493  bool PlotAvg, bool PlotMed, bool PlotMin, bool PlotMax, bool PlotSDev, bool PlotStdErr,
494  bool PlotScatter) {
495  TFltTrV AvgV, StdErrV;
496  TFltPrV AvgV2, MedV, MinV, MaxV;
497  TFltPrV ScatterV;
498  for (int i = ValMomH.FFirstKeyId(); ValMomH.FNextKeyId(i); ) {
499  TMom Mom(ValMomH[i]);
500  if (! Mom.IsDef()) { Mom.Def(); }
501  const double x = ValMomH.GetKey(i);
502  if (PlotAvg) {
503  if (PlotSDev) {
504  AvgV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
505  else {
506  AvgV2.Add(TFltPr(x, Mom.GetMean()));
507  }
508  if (PlotStdErr) {
509  StdErrV.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
510  }
511  }
512  if (PlotMed) { MedV.Add(TFltPr(x, Mom.GetMedian())); }
513  if (PlotMin) { MinV.Add(TFltPr(x, Mom.GetMn())); }
514  if (PlotMax) { MaxV.Add(TFltPr(x, Mom.GetMx())); }
515  if (PlotScatter) {
516  THashSet<TFlt> PointSet;
517  for (int xi = 0; xi < ValMomH[i].GetVals(); xi++) {
518  PointSet.AddKey(ValMomH[i].GetVal(xi)); }
519  //ScatterV.Add(TFltPr(x, ValMomH[i].GetVal(xi))); }
520  for (int xi = 0; xi < PointSet.Len(); xi++) {
521  ScatterV.Add(TFltPr(x, PointSet[xi])); }
522  //printf("S%d %d %d.", ValMomH[i].GetVals(), PointSet.Len(), ScatterV.Len());
523  }
524  }
525  AvgV.Sort(); AvgV2.Sort();
526  MedV.Sort(); MinV.Sort(); MaxV.Sort(); StdErrV.Sort();
527  TGnuPlot GP(OutFNmPref, Desc);
528  GP.SetScale(ScaleTy);
529  GP.SetXYLabel(XLabel, YLabel);
530  if (! ScatterV.Empty()) { GP.AddPlot(ScatterV, gpwPoints, "Scatter"); }
531  if (! AvgV.Empty()) { GP.AddErrBar(AvgV, "Average", "StdDev"); }
532  if (! AvgV2.Empty()) { GP.AddPlot(AvgV2, SeriesTy, "Average"); }
533  if (! MedV.Empty()) { GP.AddPlot(MedV, SeriesTy, "Median"); }
534  if (! MinV.Empty()) { GP.AddPlot(MinV, SeriesTy, "Min"); }
535  if (! MaxV.Empty()) { GP.AddPlot(MaxV, SeriesTy, "Max"); }
536  if (! StdErrV.Empty()) { GP.AddErrBar(StdErrV, "Standard error"); }
537  GP.SavePng();
538 }
539 
540 template <class TVal1>
541 void TGnuPlot::PlotValMomH(const THash<TVal1, TMom>& ValMomH1, const TStr& Label1,
542  const THash<TVal1, TMom>& ValMomH2, const TStr& Label2,
543  const TStr& OutFNmPref, const TStr& Desc, const TStr& XLabel,
544  const TStr& YLabel, const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy, bool PlotAvg,
545  bool PlotMed, bool PlotMin, bool PlotMax, bool PlotSDev, bool PlotStdErr, bool PlotScatter) {
546  TFltTrV AvgV1, AvgV2, StdErrV1, StdErrV2;
547  TFltPrV AvgVM1, MedV1, MinV1, MaxV1;
548  TFltPrV AvgVM2, MedV2, MinV2, MaxV2;
549  TFltPrV ScatterV1, ScatterV2;
550  // ValMom1
551  for (int i = ValMomH1.FFirstKeyId(); ValMomH1.FNextKeyId(i); ) {
552  TMom Mom(ValMomH1[i]);
553  if (! Mom.IsDef()) { Mom.Def(); }
554  const double x = ValMomH1.GetKey(i);
555  if (PlotAvg) {
556  if (PlotSDev) {
557  AvgV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
558  else {
559  AvgVM1.Add(TFltPr(x, Mom.GetMean()));
560  }
561  if (PlotStdErr) {
562  StdErrV1.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
563  }
564  }
565  if (PlotMed) { MedV1.Add(TFltPr(x, Mom.GetMedian())); }
566  if (PlotMin) { MinV1.Add(TFltPr(x, Mom.GetMn())); }
567  if (PlotMax) { MaxV1.Add(TFltPr(x, Mom.GetMx())); }
568  if (PlotScatter) {
569  THashSet<TFlt> PointSet;
570  for (int xi = 0; xi < ValMomH1[i].GetVals(); xi++) {
571  PointSet.AddKey(ValMomH1[i].GetVal(xi)); }
572  for (int xi = 0; xi < PointSet.Len(); xi++) {
573  ScatterV1.Add(TFltPr(x, PointSet[xi])); }
574  }
575  }
576  AvgV1.Sort(); AvgVM1.Sort(); MedV1.Sort(); MinV1.Sort(); MaxV1.Sort(); StdErrV1.Sort();
577  // ValMom2
578  for (int i = ValMomH2.FFirstKeyId(); ValMomH2.FNextKeyId(i); ) {
579  TMom Mom(ValMomH2[i]);
580  if (! Mom.IsDef()) { Mom.Def(); }
581  const double x = ValMomH2.GetKey(i);
582  if (PlotAvg) {
583  if (PlotSDev) {
584  AvgV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev())); } // std deviation
585  else {
586  AvgVM2.Add(TFltPr(x, Mom.GetMean()));
587  }
588  if (PlotStdErr) {
589  StdErrV2.Add(TFltTr(x, Mom.GetMean(), Mom.GetSDev()/sqrt((double)Mom.GetVals())));
590  }
591  }
592  if (PlotMed) { MedV2.Add(TFltPr(x, Mom.GetMedian())); }
593  if (PlotMin) { MinV2.Add(TFltPr(x, Mom.GetMn())); }
594  if (PlotMax) { MaxV2.Add(TFltPr(x, Mom.GetMx())); }
595  if (PlotScatter) {
596  THashSet<TFlt> PointSet;
597  for (int xi = 0; xi < ValMomH2[i].GetVals(); xi++) {
598  PointSet.AddKey(ValMomH2[i].GetVal(xi)); }
599  for (int xi = 0; xi < PointSet.Len(); xi++) {
600  ScatterV2.Add(TFltPr(x, PointSet[xi])); }
601  }
602  }
603  AvgV2.Sort(); AvgVM2.Sort(); MedV2.Sort(); MinV2.Sort(); MaxV2.Sort(); StdErrV2.Sort();
604  // plot
605  TGnuPlot GP(OutFNmPref, Desc);
606  GP.SetScale(ScaleTy);
607  GP.SetXYLabel(XLabel, YLabel);
608  // ValMom1
609  if (! ScatterV1.Empty()) { GP.AddPlot(ScatterV1, gpwPoints, Label1+": Scatter"); }
610  if (! AvgV1.Empty()) { GP.AddErrBar(AvgV1, Label1+": Average", Label1+": StdDev"); }
611  if (! AvgVM1.Empty()) { GP.AddPlot(AvgVM1, SeriesTy, Label1+": Average"); }
612  if (! MedV1.Empty()) { GP.AddPlot(MedV1, SeriesTy, Label1+": Median"); }
613  if (! MinV1.Empty()) { GP.AddPlot(MinV1, SeriesTy, Label1+": Min"); }
614  if (! MaxV1.Empty()) { GP.AddPlot(MaxV1, SeriesTy, Label1+": Max"); }
615  if (! StdErrV1.Empty()) { GP.AddErrBar(StdErrV1, Label1+": Std error"); }
616  // ValMom2
617  if (! ScatterV2.Empty()) { GP.AddPlot(ScatterV2, gpwPoints, Label2+": Scatter"); }
618  if (! AvgV2.Empty()) { GP.AddErrBar(AvgV2, Label2+": Average", Label2+": StdDev"); }
619  if (! AvgVM2.Empty()) { GP.AddPlot(AvgVM2, SeriesTy, Label2+": Average"); }
620  if (! MedV2.Empty()) { GP.AddPlot(MedV2, SeriesTy, Label2+": Median"); }
621  if (! MinV2.Empty()) { GP.AddPlot(MinV2, SeriesTy, Label2+": Min"); }
622  if (! MaxV2.Empty()) { GP.AddPlot(MaxV2, SeriesTy, Label2+": Max"); }
623  if (! StdErrV2.Empty()) { GP.AddErrBar(StdErrV2, Label2+": Std error"); }
624  GP.SavePng();
625 }
626 
627 template <class TVal2>
628 void TGnuPlot::PlotValOverTm(const TVec<TPair<TSecTm, TVal2> >& ValV, const TStr& OutFNmPref, const TStr& Desc,
629  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy) {
630  if (ValV.Empty()) { printf("*** Empty plot %s\n", OutFNmPref.CStr()); return; }
631  TVec<TPair<TSecTm, TVal2> > TmpV = ValV;
632  TmpV.Sort();
633  TGnuPlot GP(OutFNmPref, Desc);
634  GP.SetXYLabel(XLabel, YLabel);
635  GP.SetScale(ScaleTy);
636  GP.AddCmd("set xdata time");
637  GP.AddCmd("set timefmt \"%Y-%m-%d-%H:%M:%S\"");
638  GP.AddCmd("set format x \"%Y-%m-%d\\n%H:%M:%S\"");
639 
640  // save file
641  time_t ltime; time(&ltime);
642  char* TimeStr = ctime(&ltime); TimeStr[strlen(TimeStr) - 1] = 0;
643  FILE *F = fopen(GP.DataFNm.CStr(), "wt");
644  fprintf(F, "#\n");
645  fprintf(F, "# %s (%s)\n", Desc.CStr(), TimeStr);
646  fprintf(F, "#\n");
647  fprintf(F, "#Time\t%s\n", XLabel.CStr());
648  for (int i = 0; i < TmpV.Len(); i++) {
649  fprintf(F, "%s\t%g\n", TmpV[i].Val1.GetYmdTmStr2().CStr(), double(TmpV[i].Val2()));
650  }
651  fclose(F);
652  // plot data
653  GP.AddPlot(GP.DataFNm, 1, 2);
654  GP.SavePng();
655 }
656 
657 template <class TVal2>
658 void TGnuPlot::PlotCntOverTm(const THash<TSecTm, TVal2>& CntH, const TStr& OutFNmPref, const TStr& Desc,
659  const TStr& XLabel, const TStr& YLabel, const TGpScaleTy& ScaleTy, const TGpSeriesTy& SeriesTy) {
661  CntH.GetKeyDatPrV(TmpV);
662  PlotValOverTm(TmpV, OutFNmPref, Desc, XLabel, YLabel, ScaleTy, SeriesTy);
663 }
664 
665 #endif
666 
TGnuPlot & operator=(const TGnuPlot &GnuPlot)
Definition: gnuplot.cpp:106
int AddLinFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
Definition: gnuplot.cpp:339
TFltPr XRange
Definition: gnuplot.h:53
int AddExpFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &FitXOffset=0.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:550
void SetLineStyle(const int &PlotId, const TStr &StyleStr)
Definition: gnuplot.h:83
TStr Title
Definition: gnuplot.h:51
TStr GetFMid() const
Definition: dt.cpp:1403
static void PlotValOverTm(const TVec< TPair< TSecTm, TVal2 > > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
Definition: gnuplot.h:628
bool operator<(const TGpSeries &Gps) const
Definition: gnuplot.cpp:82
TGpSeriesTy SeriesTy
Definition: gnuplot.h:27
void SetXRange(const double &Min, const double &Max)
Definition: gnuplot.h:79
double GetMedian() const
Definition: xmath.h:244
Definition: ds.h:272
Definition: ds.h:130
static void MakeExpBins(const TFltPrV &XYValV, TFltPrV &ExpXYValV, const double &BinFactor=2, const double &MinYVal=1)
Definition: gnuplot.cpp:614
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 DataFNm
Definition: gnuplot.h:50
int GetVals() const
Definition: xmath.h:220
bool IsDef() const
Definition: xmath.h:214
TGnuPlot(const TStr &FileNm="gplot", const TStr &PlotTitle=TStr(), const bool &Grid=true)
Definition: gnuplot.cpp:86
void SetTitle(const TStr &PlotTitle)
Definition: gnuplot.h:70
void SetYLabel(const TStr &YLabel)
Definition: gnuplot.h:72
TGpSeriesCmp(const TVec< TGpSeries > &_SeriesV)
Definition: gnuplot.h:43
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:575
bool operator()(const int &Left, const int &Right) const
Definition: gnuplot.h:44
void SetXYLabel(const TStr &XLabel, const TStr &YLabel)
Definition: gnuplot.h:73
static int GetTics42()
Definition: gnuplot.cpp:26
int AddPwrFit3(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:467
Definition: xmath.h:129
static void PlotCntOverTm(const THash< TSecTm, TVal2 > &CntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
Definition: gnuplot.h:658
TKeyDat< TFlt, TFlt > TFltKd
Definition: ds.h:396
void SetDataPlotFNm(const TStr &DatFNm, const TStr &PltFNm)
Definition: gnuplot.h:74
TGpSeries & operator=(const TGpSeries &Gps)
Definition: gnuplot.cpp:70
void Plot(const TStr &Comment=TStr())
Definition: gnuplot.h:126
TStr LblY
Definition: gnuplot.h:51
TVec< TGpSeries > SeriesV
Definition: gnuplot.h:55
void SetYRange(const double &Min, const double &Max)
Definition: gnuplot.h:80
Definition: gnuplot.h:7
double GetSDev() const
Definition: xmath.h:242
int AddPwrFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
Definition: gnuplot.cpp:370
Definition: dt.h:1386
bool Empty() const
Tests whether the vector is empty.
Definition: ds.h:570
static void LoadTs(const TStr &FNm, TStrV &ColNmV, TVec< TFltKdV > &ColV)
Definition: gnuplot.cpp:665
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)
Definition: gnuplot.h:491
void Swap(TVec< TVal, TSizeTy > &Vec)
Swaps the contents of the vector with Vec.
Definition: ds.h:1101
static void SaveTs(const TIntKdV &KdV, const TStr &FNm, const TStr &HeadLn=TStr())
Definition: gnuplot.cpp:717
void AddCmd(const TStr &Cmd)
Definition: gnuplot.h:81
double GetMx() const
Definition: xmath.h:238
void Sort(const bool &Asc=true)
Sorts the elements of the vector.
Definition: ds.h:1318
Definition: gnuplot.h:7
TStr GetLineStyle(const int &PlotId) const
Definition: gnuplot.h:82
TFltKdV XYValV
Definition: gnuplot.h:28
static TStr GetSeriesTyStr(const TGpSeriesTy &SeriesTy)
Definition: gnuplot.cpp:699
const TVec< TGpSeries > & SeriesV
Definition: gnuplot.h:41
bool FNextKeyId(int &KeyId) const
Definition: hash.h:478
bool SetPause
Definition: gnuplot.h:54
int AddLogFit(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
Definition: gnuplot.cpp:519
bool SetGrid
Definition: gnuplot.h:54
void Pause(const bool &DoPause)
Definition: gnuplot.h:77
int AddKey(const TKey &Key)
Definition: shash.h:1254
int FFirstKeyId() const
Definition: hash.h:278
TTriple< TFlt, TFlt, TFlt > TFltTr
Definition: ds.h:181
bool SaveXVals() const
Definition: gnuplot.h:37
TPair< TFlt, TFlt > TFltPr
Definition: ds.h:99
void SaveEps(const int &FontSz=30, const TStr &Comment=TStr())
Definition: gnuplot.h:123
TGpScaleTy ScaleTy
Definition: gnuplot.h:52
int AddPwrFit2(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const double &MinX=-1.0, const TStr &Style=TStr())
Definition: gnuplot.cpp:419
#define EAssert(Cond)
Definition: bd.h:280
int Len() const
Definition: shash.h:1121
TStr LblX
Definition: gnuplot.h:51
int IsSameXCol(const int &CurId, const int &PrevId) const
Definition: gnuplot.cpp:758
Definition: gnuplot.h:13
void SetScale(const TGpScaleTy &GpScaleTy)
Definition: gnuplot.h:78
double GetMean() const
Definition: xmath.h:240
Definition: dt.h:412
bool Empty() const
Definition: dt.h:491
static TStr DefDataFNm
Definition: gnuplot.h:23
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
Definition: hash.h:97
static TStr GnuPlotPath
Path to GnuPlot executable. Set if gnuplot is not found in the PATH.
Definition: gnuplot.h:19
void GetKeyDatPrV(TVec< TPair< TKey, TDat > > &KeyDatPrV) const
Definition: hash.h:500
static void PlotValRank(const THash< TKey, TVal, THashFunc > &ValCntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
Definition: gnuplot.h:420
TFltPr YRange
Definition: gnuplot.h:53
int AddPlot(const TIntV &YValV, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:186
static void PlotValCntH(const THash< TKey, TVal, THashFunc > &ValCntH, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const bool &PlotCCDF=false, const bool &ExpBucket=false)
Definition: gnuplot.h:434
static TStr DefPlotFNm
Definition: gnuplot.h:22
static void Test()
Definition: gnuplot.cpp:736
void ShowGrid(const bool &Show)
Definition: gnuplot.h:76
static TStr GetScaleStr(const TGpScaleTy &ScaleTy)
Definition: gnuplot.cpp:683
int AddPwrFit1(const int &PlotId, const TGpSeriesTy &SeriesTy=gpwLines, const TStr &Style=TStr())
Definition: gnuplot.cpp:377
int AddErrBar(const TFltTrV &XYDValV, const TStr &Label=TStr())
Definition: gnuplot.cpp:265
char * CStr()
Definition: dt.h:479
TStr GetSeriesPlotStr(const int &PlotN)
Definition: gnuplot.cpp:124
void RunGnuPlot() const
Definition: gnuplot.cpp:873
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:602
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
TGpScaleTy
Definition: gnuplot.h:6
int Len() const
Definition: hash.h:228
static int Tics42
Definition: gnuplot.h:48
void CreatePlotFile(const TStr &Comment=TStr())
Definition: gnuplot.cpp:768
TGpSeriesTy
Definition: gnuplot.h:11
int AddFunc(const TStr &FuncStr, const TGpSeriesTy &SeriesTy=gpwLinesPoints, const TStr &Label=TStr(), const TStr &Style=TStr())
Definition: gnuplot.cpp:155
void SetXLabel(const TStr &XLabel)
Definition: gnuplot.h:71
static void PlotValV(const TVec< TVal1 > &ValV, const TStr &OutFNmPref, const TStr &Desc="", const TStr &XLabel="", const TStr &YLabel="", const TGpScaleTy &ScaleTy=gpsAuto, const bool &PowerFit=false, const TGpSeriesTy &SeriesTy=gpwLinesPoints)
Definition: gnuplot.h:398
TStrV MoreCmds
Definition: gnuplot.h:56
double GetMn() const
Definition: xmath.h:237
void Def()
Definition: xmath.cpp:339
const TKey & GetKey(const int &KeyId) const
Definition: hash.h:252
void Swap(TRec &Rec1, TRec &Rec2)
Definition: bd.h:568