Skip to content

Commit c92ad4c

Browse files
alexdewarBenno Evers
authored andcommitted
Optionally pass figure number to figure() as argument
1 parent dcb2322 commit c92ad4c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

matplotlibcpp.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -816,14 +816,27 @@ void text(Numeric x, Numeric y, const std::string& s = "")
816816
}
817817

818818

819-
inline long figure()
819+
inline long figure(long number = -1)
820820
{
821-
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple);
821+
PyObject *res;
822+
if (number == -1)
823+
res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, detail::_interpreter::get().s_python_empty_tuple);
824+
else {
825+
assert(number > 0);
826+
827+
// Make sure interpreter is initialised
828+
detail::_interpreter::get();
829+
830+
PyObject *args = PyTuple_New(1);
831+
PyTuple_SetItem(args, 0, PyLong_FromLong(number));
832+
res = PyObject_CallObject(detail::_interpreter::get().s_python_function_figure, args);
833+
Py_DECREF(args);
834+
}
835+
822836
if(!res) throw std::runtime_error("Call to figure() failed.");
823837

824838
PyObject* num = PyObject_GetAttrString(res, "number");
825839
if (!num) throw std::runtime_error("Could not get number attribute of figure object");
826-
827840
const long figureNumber = PyLong_AsLong(num);
828841

829842
Py_DECREF(num);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy