[python] matplotlib: improve 'grid'

This commit is contained in:
Émilie Feral
2020-03-26 14:45:29 +01:00
parent 1b768ba34a
commit 9a240bb0b4
3 changed files with 9 additions and 6 deletions

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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);