Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/prebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def gen_pyplot_functions(dub_root):
functions = filter(lambda i: i[0] != '_' or i[0] in ascii_lowercase,
extract_function_names(matplotlib.pyplot))

with open(dub_root + "/views/pyplot_functions.txt", "w") as f:
with open(dub_root + "/views/pyplot_functions.txt", "w+") as f:
f.write("\n".join(functions))


Expand Down
7 changes: 7 additions & 0 deletions source/matplotlibd/core/translate.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module matplotlibd.core.translate;

import std.traits : isArray;

alias immutable bool PyBool;
alias immutable (void*) PyNone;

Expand All @@ -19,6 +21,9 @@ string d2py(T)(T v) {
else static if (is(typeof(v) : string))
return format("\"%s\"", v);

else static if(isArray!T)
return format("np.array(%s)", v);

else
return format("%s", v);
}
Expand All @@ -33,6 +38,8 @@ unittest {
assert(d2py(false) == "False");
assert(d2py("Hello!") == "\"Hello!\"");
assert(d2py(5.iota) == "[0, 1, 2, 3, 4]");
import std.array : array;
assert(d2py(5.iota.array) == "np.array([0, 1, 2, 3, 4])");
}


Expand Down
8 changes: 4 additions & 4 deletions source/matplotlibd/pyplot.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import matplotlibd.core.translate;

private:

string py_script = "import matplotlib.pyplot as plt\n";
string py_script = "import matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nimport numpy as np\n";

immutable string plt_funcs = (){
import std.string: splitLines;
Expand Down Expand Up @@ -35,16 +35,16 @@ import matplotlibd.core.translate: False, True, None;


void clear() {
py_script = "import matplotlib.pyplot as plt\n";
py_script = "import matplotlib.pyplot as plt\nfrom mpl_toolkits.mplot3d import Axes3D\nimport numpy as np\n";
}

mixin(plt_funcs);

unittest {
import std.string;
auto script = py_script ~ "plt.plot([1, 2],[2, 4],\"r-\",lw=2)\n";
auto script = py_script ~ "plt.plot(np.array([1, 2]),np.array([2, 4]),\"r-\",lw=2)\n";
plot([1, 2], [2, 4], "r-", ["lw": 2]);
assert(script == py_script);
clear();
assert(py_script == "import matplotlib.pyplot as plt\n");
assert(py_script == "import matplotlib.pyplot as plt\nimport numpy as np\n");
}
Empty file added views/keepme
Empty file.
225 changes: 0 additions & 225 deletions views/pyplot_functions.txt

This file was deleted.