1818 python* : string
1919 script* : seq [string ]
2020 latex* : bool
21- plots* : seq [Plot ]
21+ plots* : seq [seq [ Plot ] ]
2222 font* : tuple [family: string , style: string ]
2323 dpi* : int
2424 size* : tuple [w: float , h: float ]
25+ grid* : tuple [rows: int , cols: int ]
26+ index: int
2527
2628proc save * (figure: Figure , dest: string ) =
2729 var script = newSeq [string ]()
@@ -39,8 +41,15 @@ proc save*(figure: Figure, dest: string) =
3941 script.add & " fig = plt.figure(figsize=({ figure.size.w} ,{ figure.size.h} )) "
4042 else :
4143 script.add " fig = plt.figure()"
42- for p in figure.plots:
43- script.add p.render
44+ for i in 0 ..< len (figure.plots):
45+ echo & " i = { i} "
46+ echo & " plt.subplot({ figure.grid.rows} , { figure.grid.cols} , { i+ 1 } ) "
47+ script.add & " plt.subplot({ figure.grid.rows} , { figure.grid.cols} , { i+ 1 } ) "
48+ let plots = figure.plots[i]
49+ echo & " #plots = { len (plots)} "
50+ for j in 0 ..< len (plots):
51+ echo & " j = { j} "
52+ script.add plots[j].render
4453 if figure.dpi > 0 :
4554 script.add fmt" plt.savefig('{ dest} ', format='png', transparent=False, dpi={ figure.dpi} ) "
4655 else :
@@ -51,20 +60,28 @@ proc save*(figure: Figure, dest: string) =
5160 writeFile (name, script_str)
5261 echo name
5362 discard execShellCmd fmt" /usr/local/bin/python3 { name} "
54-
55-
5663
5764proc newFigure * (): Figure =
5865 Figure (python: " /usr/local/bin/python3" ,
5966 script: newSeq [string ](),
6067 latex: false ,
6168 font: (" " , " " ),
6269 dpi: 0 ,
63- size: (0.0 , 0.0 ))
70+ size: (0.0 , 0.0 ),
71+ grid: (1 , 1 ),
72+ index: 0 ,
73+ plots: @ [])
6474
6575proc add * (figure: Figure , plot: Plot ) =
66- figure.plots.add plot
67-
76+ if len (figure.plots)== 0 :
77+ figure.plots.add @ []
78+ echo & " Add plot to { figure.index} "
79+ figure.plots[figure.index].add plot
80+
81+ proc subplot * (figure: Figure ) =
82+ figure.plots.add @ []
83+ figure.index += 1
84+
6885# Line plots
6986type LinePlot [A, B] = ref object of Plot
7087 linestyle* : string
0 commit comments