@@ -1178,3 +1178,79 @@ func ExampleLabel() {
1178
1178
}
1179
1179
}
1180
1180
```
1181
+
1182
+ ## Time series
1183
+
1184
+ ![ timeseries-example] ( https://github.com/go-hep/hep/raw/main/hplot/testdata/timeseries_monthly_golden.png )
1185
+
1186
+ [ embedmd ] :# ( ticks_example_test.go go /func ExampleTicks_monthly/ /\n}/ )
1187
+ ``` go
1188
+ func ExampleTicks_monthly () {
1189
+ cnv := epok.UTCUnixTimeConverter {}
1190
+
1191
+ p := hplot.New ()
1192
+ p.Title .Text = " Time series (monthly)"
1193
+ p.Y .Label .Text = " Goroutines"
1194
+
1195
+ p.Y .Min = 0
1196
+ p.Y .Max = 4
1197
+ p.X .AutoRescale = true
1198
+ p.X .Tick .Marker = epok.Ticks {
1199
+ Ruler: epok.Rules {
1200
+ Major: epok.Rule {
1201
+ Freq: epok.Monthly ,
1202
+ Range: epok.RangeFrom (1 , 13 , 2 ),
1203
+ },
1204
+ },
1205
+ Format: " 2006\n Jan-02\n 15:04:05" ,
1206
+ Converter: cnv,
1207
+ }
1208
+
1209
+ xysFrom := func (vs ...float64 ) plotter.XYs {
1210
+ o := make (plotter.XYs , len (vs))
1211
+ for i := range o {
1212
+ o[i].X = vs[i]
1213
+ o[i].Y = float64 (i + 1 )
1214
+ }
1215
+ return o
1216
+ }
1217
+ data := xysFrom (
1218
+ cnv.FromTime (parse (" 2010-01-02 01:02:03" )),
1219
+ cnv.FromTime (parse (" 2010-02-01 01:02:03" )),
1220
+ cnv.FromTime (parse (" 2010-02-04 11:22:33" )),
1221
+ cnv.FromTime (parse (" 2010-03-04 01:02:03" )),
1222
+ cnv.FromTime (parse (" 2010-04-05 01:02:03" )),
1223
+ cnv.FromTime (parse (" 2010-04-05 01:02:03" )),
1224
+ cnv.FromTime (parse (" 2010-05-01 00:02:03" )),
1225
+ cnv.FromTime (parse (" 2010-05-04 04:04:04" )),
1226
+ cnv.FromTime (parse (" 2010-05-08 11:12:13" )),
1227
+ cnv.FromTime (parse (" 2010-06-15 01:02:03" )),
1228
+ cnv.FromTime (parse (" 2010-07-04 04:04:43" )),
1229
+ cnv.FromTime (parse (" 2010-07-14 14:17:09" )),
1230
+ cnv.FromTime (parse (" 2010-08-04 21:22:23" )),
1231
+ cnv.FromTime (parse (" 2010-08-15 11:12:13" )),
1232
+ cnv.FromTime (parse (" 2010-09-01 21:52:53" )),
1233
+ cnv.FromTime (parse (" 2010-10-25 01:19:23" )),
1234
+ cnv.FromTime (parse (" 2010-11-30 11:32:53" )),
1235
+ cnv.FromTime (parse (" 2010-12-24 23:59:59" )),
1236
+ cnv.FromTime (parse (" 2010-12-31 23:59:59" )),
1237
+ cnv.FromTime (parse (" 2011-01-12 01:02:03" )),
1238
+ )
1239
+
1240
+ line , pnts , err := hplot.NewLinePoints (data)
1241
+ if err != nil {
1242
+ log.Fatalf (" could not create plotter: %+v " , err)
1243
+ }
1244
+
1245
+ line.Color = color.RGBA {B: 255 , A: 255 }
1246
+ pnts.Shape = draw.CircleGlyph {}
1247
+ pnts.Color = color.RGBA {R: 255 , A: 255 }
1248
+
1249
+ p.Add (line, pnts, hplot.NewGrid ())
1250
+
1251
+ err = p.Save (20 *vg.Centimeter , 10 *vg.Centimeter , " testdata/timeseries_monthly.png" )
1252
+ if err != nil {
1253
+ log.Fatalf (" could not save plot: %+v " , err)
1254
+ }
1255
+ }
1256
+ ```
0 commit comments