feat: add contextlib

This commit is contained in:
Shunsuke Shibayama 2023-06-29 15:03:56 +09:00
parent 1eabc1f0c0
commit d03dcbd392
3 changed files with 31 additions and 6 deletions

View file

@ -1 +1,5 @@
.Figure: ClassType
axes = pyimport "./axes"
.Figure!: ClassType
.Figure!.
add_axes!: (self: RefMut(.Figure!), rect: [Nat; 4], projection := Str or NoneType, polar := Bool, label := Str) => axes.Axes!

View file

@ -1,3 +1,5 @@
contextlib = pyimport "contextlib"
# lines = pyimport "../lines"
text = pyimport "../text"
legend = pyimport "../legend"
@ -10,9 +12,16 @@ axes = pyimport "../axes"
.title!: (title: Str) => text.Text
.xlabel!: (label: Str) => text.Text
.ylabel!: (label: Str) => text.Text
.xlim!: (left := Float, right := Float) => (Float, Float) \
and ((left_right: (Float, Float)) => (Float, Float))
.ylim!: (bottom := Float, top := Float) => (Float, Float) \
and ((bottom_top: (Float, Float)) => (Float, Float))
.legend!: (labels := [Str; _]) => legend.Legend
.subplots!: (() => (figure.Figure, axes.Axes!)) \
and ((nrows: {1}, ncols: {1}) => (figure.Figure, axes.Axes!)) \
and ((nrows: {1}, ncols: Nat) => (figure.Figure, [axes.Axes!; _])) \
and ((nrows: Nat, ncols: {1}) => (figure.Figure, [axes.Axes!; _])) \
and ((nrows: Nat, ncols: Nat) => (figure.Figure, [[axes.Axes!; _]; _]))
.savefig!: (fname: Str, dpi := Float or Str, format := Str) => NoneType
.subplots!: (() => (figure.Figure!, axes.Axes!)) \
and ((nrows: {1}, ncols: {1}) => (figure.Figure!, axes.Axes!)) \
and ((nrows: {1}, ncols: Nat) => (figure.Figure!, [axes.Axes!; _])) \
and ((nrows: Nat, ncols: {1}) => (figure.Figure!, [axes.Axes!; _])) \
and ((nrows: Nat, ncols: Nat) => (figure.Figure!, [[axes.Axes!; _]; _]))
.figure!: (num := Int or Str, figsize := [Float; _], dpi := Float) => figure.Figure!
.xkcd!: (scale := Float, length := Float, randomness := Float) => contextlib.ExitStack!