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

hist function can now take into account the following keyword arguments :
- color

Change-Id: I69eca6555d892db958d2bd002f438a40908b2d9d
This commit is contained in:
Arthur Camouseigt
2020-05-25 14:31:40 +02:00
committed by Émilie Feral
parent 0e3684e137
commit 5daaa2c050
3 changed files with 8 additions and 5 deletions

View File

@@ -251,14 +251,14 @@ mp_obj_t modpyplot_grid(size_t n_args, const mp_obj_t *args) {
return mp_const_none;
}
/* hist(x, bins, color)
/* hist(x, bins KW : color)
* 'x' array
* 'bins': (default value 10)
* - int (number of bins)
* - sequence of bins
* */
mp_obj_t modpyplot_hist(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 ) {
assert(sPlotStore != nullptr);
sPlotStore->setShow(true);
// Sort data to easily get the minimal and maximal value and count bin sizes
@@ -330,7 +330,10 @@ mp_obj_t modpyplot_hist(size_t n_args, const mp_obj_t *args) {
binIndex++;
}
KDColor color = colorFromOptionalArgumentAtIndex(n_args, args, 2);
// Setting hist 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<nBins; i++) {
sPlotStore->addRect(edgeItems[i], edgeItems[i+1], binItems[i], mp_obj_new_float(0.0), color);
}

View File

@@ -8,7 +8,7 @@ mp_obj_t modpyplot_arrow(size_t n_args, const mp_obj_t *args, mp_map_t* kw_args)
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);
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_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_text(mp_obj_t x, mp_obj_t y, mp_obj_t s);

View File

@@ -5,7 +5,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_KW(modpyplot_arrow_obj, 4, modpyplot_arrow);
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(modpyplot_axis_obj, 0, 1, modpyplot_axis);
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_VAR_BETWEEN(modpyplot_hist_obj, 1, 3, modpyplot_hist);
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_0(modpyplot_show_obj, modpyplot_show);