10000 Fix implementation of errorbar() · whuyao/matplotlib-cpp@16a7fd6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 16a7fd6

Browse files
alexdewarlava
authored andcommitted
Fix implementation of errorbar()
At the moment, the errorbar() function takes an optional parameter s, which is presumably supposed to correspond to the same parameter for e.g. the plot function. The only problem is that a) this argument is unused in the function and b) matplotlib's errorbar() doesn't take a parameter like this anyway. I've replaced the s argument with an optional keywords argument, as for other functions, which allows for setting colour, marker style etc.
1 parent 6e3fcf6 commit 16a7fd6

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

matplotlibcpp.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,20 +576,23 @@ bool loglog(const std::vector<NumericX>& x, const std::vector<NumericY>& y, cons
576576
}
577577

578578
template<typename NumericX, typename NumericY>
579-
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::string &s = "")
579+
bool errorbar(const std::vector<NumericX> &x, const std::vector<NumericY> &y, const std::vector<NumericX> &yerr, const std::map<std::string, std::string> &keywords = {})
580580
{
581581
assert(x.size() == y.size());
582582

583583
PyObject* xarray = get_array(x);
584584
PyObject* yarray = get_array(y);
585585
PyObject* yerrarray = get_array(yerr);
586586

587-
PyObject *kwargs = PyDict_New();
587+
// construct keyword args
588+
PyObject* kwargs = PyDict_New();
589+
for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it)
590+
{
591+
PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str()));
592+
}
588593

589594
PyDict_SetItemString(kwargs, "yerr", yerrarray);
590595

591-
PyObject *pystring = PyString_FromString(s.c_str());
592-
593596
PyObject *plot_args = PyTuple_New(2);
594597
PyTuple_SetItem(plot_args, 0, xarray);
595598
PyTuple_SetItem(plot_args, 1, yarray);
@@ -766,7 +769,7 @@ inline void figure_size(size_t w, size_t h)
766769
PyDict_SetItemString(kwargs, "figsize", size);
767770
PyDict_SetItemString(kwargs, "dpi", PyLong_FromSize_t(dpi));
768771

769-
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_figure,
772+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_figure,
770773
detail::_interpreter::get().s_python_empty_tuple, kwargs);
771774

772775
Py_DECREF(kwargs);
@@ -890,7 +893,7 @@ inline void xticks(const std::vector<Numeric> &ticks, const std::vector<std::str
890893
Py_DECREF(args);
891894
Py_DECREF(kwargs);
892895
if(!res) throw std::runtime_error("Call to xticks() failed");
893-
896+
894897
Py_DECREF(res);
895898
}
896899

@@ -937,7 +940,7 @@ inline void yticks(const std::vector<Numeric> &ticks, const std::vector<std::str
937940
Py_DECREF(args);
938941
Py_DECREF(kwargs);
939942
if(!res) throw std::runtime_error("Call to yticks() failed");
940-
943+
941944
Py_DECREF(res);
942945
}
943946

0 commit comments

Comments
 (0)
0