Skip to content

Commit d430c69

Browse files
author
Martino
committed
Added xlim() and ylim() to get the limits of a plot
1 parent 94a4102 commit d430c69

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

matplotlibcpp.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,38 @@ namespace matplotlibcpp {
354354
Py_DECREF(args);
355355
Py_DECREF(res);
356356
}
357+
358+
359+
double * xlim()
360+
{
361+
PyObject* args = PyTuple_New(0);
362+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_xlim, args);
363+
PyObject * left = PyTuple_GetItem(res,0);
364+
PyObject * right = PyTuple_GetItem(res,1);
365+
double * arr = new double[2];
366+
arr[0] = PyFloat_AsDouble(left);
367+
arr[1] = PyFloat_AsDouble(right);
368+
369+
if(!res) throw std::runtime_error("Call to xlim() failed.");
370+
Py_DECREF(res);
371+
return arr;
372+
}
373+
374+
375+
double * ylim()
376+
{
377+
PyObject* args = PyTuple_New(0);
378+
PyObject* res = PyObject_CallObject(detail::_interpreter::get().s_python_function_ylim, args);
379+
PyObject * left = PyTuple_GetItem(res,0);
380+
PyObject * right = PyTuple_GetItem(res,1);
381+
double * arr = new double[2];
382+
arr[0] = PyFloat_AsDouble(left);
383+
arr[1] = PyFloat_AsDouble(right);
384+
385+
if(!res) throw std::runtime_error("Call to ylim() failed.");
386+
Py_DECREF(res);
387+
return arr;
388+
}
357389

358390
inline void subplot(long nrows, long ncols, long plot_number) {
359391
// construct positional args

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