Skip to content

Commit b3de4d7

Browse files
committed
Add support for horizontal and vertical limits
1 parent b4f0717 commit b3de4d7

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

docs/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,22 @@ for n in 0..<9:
183183
```
184184

185185
![plot](grid.png)
186+
187+
### horizontal and vertical limits
188+
189+
```nim
190+
let x10 = rnorm(1000, 0.0, 2.0)
191+
let y10 = rnorm(1000, 0.0, 2.0)
192+
let figure10 = newFigure()
193+
figure10.size = (8.0, 4.0)
194+
figure10.grid = (1, 2)
195+
let sp10 = newScatterPlot(x10, y10)
196+
figure10.add newXLimit(0.0, 1.0)
197+
figure10.add sp10
198+
figure10.subplot
199+
figure10.add newYLimit(-1.0, 0.0)
200+
figure10.add sp10
201+
figure10.save("docs/limits.png")
202+
```
203+
204+
![plot](limits.png)

docs/examples.nim

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,17 @@ for n in 0..<9:
119119
lp.colour = "red"
120120
figure9.add lp
121121
figure9.save("docs/grid.png")
122+
123+
### horizontal and vertical limits
124+
let x10 = rnorm(1000, 0.0, 2.0)
125+
let y10 = rnorm(1000, 0.0, 2.0)
126+
let figure10 = newFigure()
127+
figure10.size = (8.0, 4.0)
128+
figure10.grid = (1, 2)
129+
let sp10 = newScatterPlot(x10, y10)
130+
figure10.add newXLimit(0.0, 1.0)
131+
figure10.add sp10
132+
figure10.subplot
133+
figure10.add newYLimit(-1.0, 0.0)
134+
figure10.add sp10
135+
figure10.save("docs/limits.png")

docs/limits.png

33.7 KB
Loading

src/matplotnim.nim

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,23 @@ method render[A,B](this: Annotation[A,B]): string =
231231
return &"ax=plt.gca()\nax.annotate('{this.text}', xy=({this.x}, {this.y}))"
232232

233233
proc newAnnotation*[A,B](x: A, y: B, text: string): Annotation[A,B] =
234-
Annotation[A,B](x: x, y: y, text: text, colour: "")
234+
Annotation[A,B](x: x, y: y, text: text, colour: "")
235+
236+
# Limits
237+
type XLimit[A] = ref object of Plot
238+
min: A
239+
max: A
240+
method render[A](this: XLimit[A]): string =
241+
return &"ax=plt.gca()\nax.set_xlim([{this.min},{this.max}])"
242+
243+
proc newXLimit*[A](min: A, max: A): XLimit[A] =
244+
XLimit[A](min: min, max: max)
245+
246+
type YLimit[A] = ref object of Plot
247+
min: A
248+
max: A
249+
method render[A](this: YLimit[A]): string =
250+
return &"ax=plt.gca()\nax.set_ylim([{this.min},{this.max}])"
251+
252+
proc newYLimit*[A](min: A, max: A): YLimit[A] =
253+
YLimit[A](min: min, max: max)

0 commit comments

Comments
 (0)