[matplotlib/modpyplot.cpp] Adding keyword arguments support for scatter function

scatter function can now take into account the following keywords arguments :
- color

Change-Id: Iaea5a7a46d25e3efe2214368334ce859900d6ae6
This commit is contained in:
Arthur Camouseigt
2020-05-25 14:35:52 +02:00
committed by Émilie Feral
parent 5daaa2c050
commit b26d448573
3 changed files with 8 additions and 5 deletions

View File

@@ -340,19 +340,22 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args )
return mp_const_none;
}
/* scatter(x, y, color)
/* scatter(x, y, KW : color)
* - x, y: list
* - x, y: scalar
* */
mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args) {
mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args) {
assert(sPlotStore != nullptr);
sPlotStore->setShow(true);
mp_obj_t * xItems, * yItems;
assert(n_args >= 2);
size_t length = extractArgumentsAndCheckEqualSize(args[0], args[1], &xItems, &yItems);
KDColor color = colorFromOptionalArgumentAtIndex(n_args, args, 2);
// Setting scatter color
mp_map_elem_t * elem = mp_map_lookup(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_color), MP_MAP_LOOKUP);
KDColor color = colorFromKeywordArgument(elem);
for (size_t i=0; i<length; i++) {
sPlotStore->addDot(xItems[i], yItems[i], color);
}

View File

@@ -10,6 +10,6 @@ mp_obj_t modpyplot_bar(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args);
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);
mp_obj_t modpyplot_plot(size_t n_args, const mp_obj_t *args);
mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args);
mp_obj_t modpyplot_scatter(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args);
mp_obj_t modpyplot_text(mp_obj_t x, mp_obj_t y, mp_obj_t s);
mp_obj_t modpyplot_show();

View File

@@ -7,7 +7,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_bar_obj, 2, modpyplot_bar);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_grid_obj, 0, 1, modpyplot_grid);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_hist_obj, 1, modpyplot_hist);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_plot_obj, 1, 3, modpyplot_plot);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_scatter_obj, 2, 3, modpyplot_scatter);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_scatter_obj, 2, modpyplot_scatter);
STATIC MP_DEFINE_CONST_FUN_OBJ_0(modpyplot_show_obj, modpyplot_show);
STATIC MP_DEFINE_CONST_FUN_OBJ_3(modpyplot_text_obj, modpyplot_text);