diff --git a/python/port/mod/matplotlib/modpyplot.cpp b/python/port/mod/matplotlib/modpyplot.cpp index 7a6b332f6..9ef3cef02 100644 --- a/python/port/mod/matplotlib/modpyplot.cpp +++ b/python/port/mod/matplotlib/modpyplot.cpp @@ -121,11 +121,14 @@ mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height) { return mp_const_none; } -mp_obj_t modpyplot_grid(mp_obj_t b) { - if (mp_obj_is_type(b, &mp_type_bool)) { - sPlotStore->setGridRequested(mp_obj_is_true(b)); - } else { +mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args) { + assert(sPlotStore != nullptr); + + if (n_args == 0) { + // Toggle the grid visibility sPlotStore->setGridRequested(!sPlotStore->gridRequested()); + } else { + sPlotStore->setGridRequested(mp_obj_is_true(args[0])); } return mp_const_none; } diff --git a/python/port/mod/matplotlib/modpyplot.h b/python/port/mod/matplotlib/modpyplot.h index c016ab042..00499a7bd 100644 --- a/python/port/mod/matplotlib/modpyplot.h +++ b/python/port/mod/matplotlib/modpyplot.h @@ -6,7 +6,7 @@ void modpyplot_gc_collect(); mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args); mp_obj_t modpyplot_axis(size_t n_args, const mp_obj_t *args); mp_obj_t modpyplot_bar(mp_obj_t x, mp_obj_t height); -mp_obj_t modpyplot_grid(mp_obj_t b); +mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args); mp_obj_t modpyplot_hist(mp_obj_t x); mp_obj_t modpyplot_plot(mp_obj_t x, mp_obj_t y); mp_obj_t modpyplot_scatter(mp_obj_t x, mp_obj_t y); diff --git a/python/port/mod/matplotlib/modpyplot_table.c b/python/port/mod/matplotlib/modpyplot_table.c index 2c092dd02..00224395a 100644 --- a/python/port/mod/matplotlib/modpyplot_table.c +++ b/python/port/mod/matplotlib/modpyplot_table.c @@ -4,7 +4,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(modpyplot___init___obj, modpyplot___init__); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_arrow_obj, 4, 4, modpyplot_arrow); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_axis_obj, 0, 1, modpyplot_axis); STATIC MP_DEFINE_CONST_FUN_OBJ_2(modpyplot_bar_obj, modpyplot_bar); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(modpyplot_grid_obj, modpyplot_grid); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_grid_obj, 0, 1, modpyplot_grid); STATIC MP_DEFINE_CONST_FUN_OBJ_1(modpyplot_hist_obj, modpyplot_hist); STATIC MP_DEFINE_CONST_FUN_OBJ_2(modpyplot_plot_obj, modpyplot_plot); STATIC MP_DEFINE_CONST_FUN_OBJ_2(modpyplot_scatter_obj, modpyplot_scatter);