@@ -94,6 +94,7 @@ struct _interpreter {
9494 PyObject *s_python_function_bar;
9595 PyObject *s_python_function_subplots_adjust;
9696 PyObject *s_python_function_imshow;
97+ PyObject *s_python_function_colorbar;
9798
9899 /* For now, _interpreter is implemented as a singleton since its currently not
99100 possible to have multiple independent embedded python interpreters without
@@ -229,12 +230,13 @@ struct _interpreter {
229230 s_python_function_subplots_adjust =
230231 PyObject_GetAttrString (pymod, " subplots_adjust" );
231232 s_python_function_imshow = PyObject_GetAttrString (pymod, " imshow" );
233+ s_python_function_colorbar = PyObject_GetAttrString (pymod, " colorbar" );
232234
233235 if (!s_python_function_show || !s_python_function_close ||
234236 !s_python_function_draw || !s_python_function_pause ||
235237 !s_python_function_figure || !s_python_function_fignum_exists ||
236238 !s_python_function_plot || !s_python_function_quiver ||
237- !s_python_function_contour ||
239+ !s_python_function_contour || !s_python_function_colorbar ||
238240 !s_python_function_semilogx || !s_python_function_semilogy ||
239241 !s_python_function_loglog || !s_python_function_fill ||
240242 !s_python_function_fill_between || !s_python_function_subplot ||
@@ -296,7 +298,8 @@ struct _interpreter {
296298 !PyFunction_Check (s_python_function_suptitle) ||
297299 !PyFunction_Check (s_python_function_bar) ||
298300 !PyFunction_Check (s_python_function_subplots_adjust) ||
299- !PyFunction_Check (s_python_function_imshow)
301+ !PyFunction_Check (s_python_function_imshow) ||
302+ !PyFunction_Check (s_python_function_colorbar)
300303 ) {
301304 throw std::runtime_error (
302305 " Python object is unexpectedly not a PyFunction." );
@@ -686,6 +689,15 @@ void imshow(const Matrix& X, const std::map<std::string, std::string> &keywords
686689 Py_DECREF (res);
687690}
688691
692+ // @brief Add the colorbar
693+ void colorbar () {
694+ PyObject *res =
695+ PyObject_CallObject (detail::_interpreter::get ().s_python_function_colorbar ,
696+ detail::_interpreter::get ().s_python_empty_tuple );
697+ if (!res)
698+ throw std::runtime_error (" Call to colorbar() failed." );
699+ }
700+
689701// @brief plot_surface for datapoints (x_ij, y_ij, z_ij) with i,j = 0..n
690702// @param x The x values of the datapoints in a matrix
691703// @param y The y values of the datapoints in a matrix
0 commit comments