-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4cb7e9b
commit 55a5dbd
Showing
10 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
*.annot | ||
*.cmo | ||
*.cma | ||
*.cmi | ||
*.a | ||
*.o | ||
*.cmx | ||
*.cmxs | ||
*.cmxa | ||
*.swp | ||
*.ipynb_checkpoints | ||
|
||
# ocamlbuild working directory | ||
_build/ | ||
|
||
# dataset directory | ||
data/ | ||
|
||
# ocamlbuild targets | ||
*.byte | ||
*.native | ||
|
||
# oasis generated files | ||
setup.data | ||
setup.log | ||
torch.install | ||
|
||
# Merlin configuring file for Vim and Emacs | ||
.merlin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2018 Laurent Mazare | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
all: | ||
dune build @install | ||
|
||
plot: .FORCE | ||
dune build examples/plot.exe | ||
_build/default/examples/plot.exe | ||
|
||
clean: | ||
rm -Rf _build | ||
|
||
.FORCE: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(lang dune 1.4) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(executables | ||
(names plot) | ||
(libraries base matplotlib)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
open Base | ||
|
||
let () = | ||
let plt = Matplotlib.init Default in | ||
let xys = | ||
List.init 120 ~f:(fun i -> | ||
let i = Float.of_int i in | ||
i, Float.sin (i /. 20.)) | ||
in | ||
Matplotlib.xlabel plt "x"; | ||
Matplotlib.ylabel plt "sin(x)"; | ||
Matplotlib.grid plt true; | ||
Matplotlib.plot plt ~xys; | ||
Matplotlib.savefig plt "test.png"; | ||
Matplotlib.show plt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
opam-version: "2.0" | ||
name: "matplotlib" | ||
bug-reports: "https://github.com/LaurentMazare/ocaml-matplotlib/issues" | ||
homepage: "https://github.com/LaurentMazare/ocaml-matplotlib" | ||
dev-repo: "git+https://github.com/LaurentMazare/ocaml-matplotlib.git" | ||
maintainer: "Laurent Mazare <[email protected]>" | ||
authors: [ "Laurent Mazare" ] | ||
|
||
version: "dev" | ||
|
||
build: [["dune" "build" "-j" jobs "@install"]] | ||
|
||
install: [] | ||
remove: [] | ||
|
||
depends: [ | ||
"base" {>= "0.11.0"} | ||
"stdio" | ||
"pyml" | ||
"jupyter" | ||
"dune" {build} | ||
"ocaml" {>= "4.06"} | ||
] | ||
|
||
depopts: [ | ||
] | ||
|
||
conflicts: [ | ||
] | ||
|
||
available: [ | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
(library | ||
(name matplotlib) | ||
(public_name matplotlib) | ||
(flags (-linkall)) | ||
(libraries base pyml)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
open Base | ||
open Pyops | ||
|
||
module Backend = struct | ||
type t = | ||
| Agg | ||
| Default | ||
|
||
let to_string_option = function | ||
| Agg -> Some "Agg" | ||
| Default -> None | ||
end | ||
|
||
type t = Py.Object.t | ||
|
||
let init backend = | ||
Py.initialize (); | ||
let plt = Py.import "matplotlib.pyplot" in | ||
Option.iter (Backend.to_string_option backend) ~f:(fun backend_str -> | ||
ignore (plt.&("switch_backend")[| Py.String.of_string backend_str |])); | ||
plt | ||
|
||
let xlabel t label = | ||
ignore (t.&("xlabel")[| Py.String.of_string label |]) | ||
|
||
let ylabel t label = | ||
ignore (t.&("ylabel")[| Py.String.of_string label |]) | ||
|
||
let grid t b = | ||
ignore (t.&("grid")[| Py.Bool.of_bool b |]) | ||
|
||
let savefig t filename = | ||
ignore (t.&("savefig")[| Py.String.of_string filename |]) | ||
|
||
let plot t ~xys = | ||
let xs, ys = List.unzip xys in | ||
let xs = List.map xs ~f:Py.Float.of_float |> Py.List.of_list in | ||
let ys = List.map ys ~f:Py.Float.of_float |> Py.List.of_list in | ||
ignore (t.&("plot")[| xs; ys |]) | ||
|
||
let show t = | ||
ignore (t.&("show")[| |]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
type t | ||
|
||
module Backend : sig | ||
type t = | ||
| Agg | ||
| Default | ||
end | ||
|
||
val init : Backend.t -> t | ||
val xlabel : t -> string -> unit | ||
val ylabel : t -> string -> unit | ||
val grid : t -> bool -> unit | ||
val plot : t -> xys:(float * float) list -> unit | ||
val show : t -> unit | ||
val savefig : t -> string -> unit |