Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dcb2322

Browse files
alexdewarBenno Evers
authored and
Benno Evers
committed
Return figure number from figure function
1 parent b124207 commit dcb2322

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

matplotlibcpp.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,20 @@ void text(Numeric x, Numeric y, const std::string& s = "")
816816
}
817817

818818

819-
inline void figure()
819+
inline long figure()
820820
{
821821
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple);
822822
if(!res) throw std::runtime_error("Call to figure() failed.");
823823

824+
PyObject* num = PyObject_GetAttrString(res, "number");
825+
if (!num) throw std::runtime_error("Could not get number attribute of figure object");
826+
827+
const long figureNumber = PyLong_AsLong(num);
828+
829+
Py_DECREF(num);
824830
Py_DECREF(res);
831+
832+
return figureNumber;
825833
}
826834

827835
inline void figure_size(size_t w, size_t h)

0 commit comments

Comments
 (0)