@@ -501,33 +501,33 @@ bool plot(const VectorY &y,
501501template <typename VectorX, typename VectorY>
502502bool loglog (const VectorX &x, const VectorY &y, const std::string &s = " " ,
503503 const std::map<std::string, std::string> &keywords = {}) {
504- detail::_interpreter::get ( );
504+ assert (x. size () == y. size () );
505505
506- // argument for xscale/yscale is only the string "log"
507- PyObject *log_arg = PyTuple_New (1 );
508- PyObject *pystring = PyString_FromString (" log" );
509- PyTuple_SetItem (log_arg, 0 , pystring);
506+ PyObject *xarray = get_array (x);
507+ PyObject *yarray = get_array (y);
510508
511- // call xscale("log") and yscale("log"), no kwargs needed hence pass NULL,
512- // as explained in https://docs.python.org/3/c-api/object.html
513- PyObject *res_x = PyObject_Call (
514- detail::_interpreter::get ().s_python_function_xscale , log_arg, NULL );
515- PyObject *res_y = PyObject_Call (
516- detail::_interpreter::get ().s_python_function_yscale , log_arg, NULL );
509+ PyObject *pystring = PyString_FromString (s.c_str ());
517510
518- // clean up
519- Py_DECREF (log_arg);
511+ PyObject *plot_args = PyTuple_New (3 );
512+ PyTuple_SetItem (plot_args, 0 , xarray);
513+ PyTuple_SetItem (plot_args, 1 , yarray);
514+ PyTuple_SetItem (plot_args, 2 , pystring);
515+
516+ PyObject *kwargs = PyDict_New ();
517+ for (auto const &item : keywords) {
518+ PyDict_SetItemString (kwargs, item.first .c_str (),
519+ PyString_FromString (item.second .c_str ()));
520+ }
520521
521- if (!res_x)
522- throw std::runtime_error (" Call to xscale() failed" );
523- Py_DECREF (res_x);
522+ PyObject *res = PyObject_Call (
523+ detail::_interpreter::get ().s_python_function_loglog , plot_args, kwargs);
524524
525- if (!res_y)
526- throw std::runtime_error (" Call to yscale() failed" );
527- Py_DECREF (res_y);
525+ Py_DECREF (plot_args);
526+ Py_DECREF (kwargs);
527+ if (res)
528+ Py_DECREF (res);
528529
529- // call plot, which gets now plotted in doubly logarithmic scale
530- return plot (x, y, s, keywords);
530+ return res;
531531}
532532
533533template <typename VectorX, typename VectorY>
0 commit comments