diff --git a/python/port/mod/matplotlib/pyplot/modpyplot.cpp b/python/port/mod/matplotlib/pyplot/modpyplot.cpp index a327ac0db..df087c2b4 100644 --- a/python/port/mod/matplotlib/pyplot/modpyplot.cpp +++ b/python/port/mod/matplotlib/pyplot/modpyplot.cpp @@ -98,6 +98,10 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args) assert(sPlotStore != nullptr); sPlotStore->setShow(true); + if (n_args > 4) { + mp_raise_TypeError("arrow() takes 4 positional arguments"); + } + mp_map_elem_t * elem; // Setting arrow width elem = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_head_width), MP_MAP_LOOKUP); @@ -172,6 +176,9 @@ mp_obj_t modpyplot_axis(size_t n_args, const mp_obj_t *args) { mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args) { assert(sPlotStore != nullptr); + if (n_args > 4) { + mp_raise_TypeError("bar() takes 4 positional arguments"); + } sPlotStore->setShow(true); mp_obj_t * xItems; mp_obj_t * hItems; @@ -248,6 +255,9 @@ mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args) { * */ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args ) { + if (n_args > 3) { + mp_raise_TypeError("hist() takes 3 positional arguments"); + } assert(sPlotStore != nullptr); sPlotStore->setShow(true); // Sort data to easily get the minimal and maximal value and count bin sizes @@ -336,6 +346,9 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args ) mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args) { assert(sPlotStore != nullptr); + if (n_args > 2) { + mp_raise_TypeError("scatter() takes 2 positional arguments"); + } sPlotStore->setShow(true); mp_obj_t * xItems, * yItems; assert(n_args >= 2); @@ -358,6 +371,9 @@ mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args, mp_map_t* kw_arg mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args,mp_map_t* kw_args) { assert(sPlotStore != nullptr); + if (n_args > 2) { + mp_raise_TypeError("plot() takes 2 positional arguments"); + } sPlotStore->setShow(true); mp_obj_t * xItems, * yItems; size_t length; diff --git a/python/test/matplotlib.cpp b/python/test/matplotlib.cpp index dbb2dde49..99bc61f5c 100644 --- a/python/test/matplotlib.cpp +++ b/python/test/matplotlib.cpp @@ -35,9 +35,11 @@ QUIZ_CASE(python_matplotlib_pyplot_arrow) { TestExecutionEnvironment env = init_environement(); assert_command_execution_succeeds(env, "from matplotlib.pyplot import *"); assert_command_execution_succeeds(env, "arrow(2,3,4,5)"); - assert_command_execution_succeeds(env, "arrow(2,3,4,5, 0.1)"); + assert_command_execution_fails(env, "arrow(2,3,4,5, 0.1)"); assert_command_execution_fails(env, "arrow(2,3,4,5, \"width\")"); - assert_command_execution_succeeds(env, "arrow(2,3,4,5, 0.1, \"#FF00FF\")"); + assert_command_execution_fails(env, "arrow(2,3,4,5, 0.1, \"#FF00FF\")"); + assert_command_execution_succeeds(env, "arrow(2,3,4,5,head_width=0.3)"); + assert_command_execution_succeeds(env, "arrow(2,3,4,5,color=\"red\")"); assert_command_execution_succeeds(env, "show()"); deinit_environment(); } @@ -62,7 +64,7 @@ QUIZ_CASE(python_matplotlib_pyplot_bar) { assert_command_execution_succeeds(env, "bar([],[])"); assert_command_execution_succeeds(env, "bar([1,2,3],[1,2,3],2,3)"); assert_command_execution_succeeds(env, "bar([1,2,3],[1,2,3],[1,2,3],[1,2,3])"); - assert_command_execution_succeeds(env, "bar([1,2,3],[1,2,3],[1,2,3],[1,2,3], \"orange\")"); + assert_command_execution_succeeds(env, "bar([1,2,3],[1,2,3],[1,2,3],[1,2,3], color=\"orange\")"); assert_command_execution_succeeds(env, "show()"); assert_command_execution_fails(env, "bar([1,2,3],[1,2,3,4],[1,2,3],[1,2,3])"); deinit_environment(); @@ -94,7 +96,7 @@ QUIZ_CASE(python_matplotlib_pyplot_plot) { assert_command_execution_succeeds(env, "plot([2,3,4,5,6])"); assert_command_execution_succeeds(env, "plot(2,3)"); assert_command_execution_succeeds(env, "plot([2,3,4,5,6],[3,4,5,6,7])"); - assert_command_execution_succeeds(env, "plot([2,3,4,5,6],[3,4,5,6,7], \"g\")"); + assert_command_execution_succeeds(env, "plot([2,3,4,5,6],[3,4,5,6,7], color=\"g\")"); assert_command_execution_succeeds(env, "show()"); assert_command_execution_fails(env, "plot([2,3,4,5,6],2)"); deinit_environment(); @@ -105,7 +107,7 @@ QUIZ_CASE(python_matplotlib_pyplot_scatter) { assert_command_execution_succeeds(env, "from matplotlib.pyplot import *"); assert_command_execution_succeeds(env, "scatter(2,3)"); assert_command_execution_succeeds(env, "scatter([2,3,4,5,6],[3,4,5,6,7])"); - assert_command_execution_succeeds(env, "scatter([2,3,4,5,6],[3,4,5,6,7], (0,0,255))"); + assert_command_execution_succeeds(env, "scatter([2,3,4,5,6],[3,4,5,6,7], color=(0,0,255))"); assert_command_execution_succeeds(env, "show()"); assert_command_execution_fails(env, "scatter([2,3,4,5,6],2)"); deinit_environment();