8000 Add set_xscale and set_yscale · lava/matplotlib-cpp@a179e3b · GitHub
[go: up one dir, main page]

Skip to content

Commit a179e3b

Browse files
committed
Add set_xscale and set_yscale
1 parent ef0383f commit a179e3b

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

matplotlibcpp.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ struct _interpreter {
7070
PyObject *s_python_function_subplot2grid;
7171
PyObject *s_python_function_legend;
7272
PyObject *s_python_function_xlim;
73+
PyObject *s_python_function_set_xscale;
74+
PyObject *s_python_function_set_yscale;
7375
PyObject *s_python_function_ion;
7476
PyObject *s_python_function_ginput;
7577
PyObject *s_python_function_ylim;
@@ -246,6 +248,8 @@ struct _interpreter {
246248
s_python_function_subplot2grid = safe_import(pymod, "subplot2grid");
247249
s_python_function_legend = safe_import(pymod, "legend");
248250
s_python_function_xlim = safe_import(pymod, "xlim");
251+
s_python_function_set_xscale = safe_import(pymod, "set_xscale");
252+
s_python_function_set_yscale = safe_import(pymod, "set_yscale");
249253
s_python_function_ylim = safe_import(pymod, "ylim");
250254
s_python_function_title = safe_import(pymod, "title");
251255
s_python_function_axis = safe_import(pymod, "axis");
@@ -883,6 +887,52 @@ bool arrow(Numeric x, Numeric y, Numeric end_x, Numeric end_y, const std::string
883887
return res;
884888
}
885889

890+
void set_xscale(std::string value,
891+
const std::map<std::string, std::string> &keywords = {})
892+
{
893+
detail::_interpreter::get();
894+
895+
PyObject* pystr = PyString_FromString(value.c_str());
896+
PyObject* args = PyTuple_New(1);
897+
PyTuple_SetItem(args, 0, pystr);
898+
899+
PyObject* kwargs = PyDict_New();
900+
for (auto it = keywords.begin(); it != keywords.end(); ++it) {
901+
PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
902+
}
903+
904+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_set_xscale, args, kwargs);
905+
906+
if(!res) throw std::runtime_error("Call to set_xscale() failed.");
907+
908+
Py_DECREF(args);
909+
Py_DECREF(kwargs);
910+
Py_DECREF(res);
911+
}
912+
913+
void set_yscale(std::string value,
914+
const std::map<std::string, std::string> &keywords = {})
915+
{
916+
detail::_interpreter::get();
917+
918+
PyObject* pystr = PyString_FromString(value.c_str());
919+
PyObject* args = PyTuple_New(1);
920+
PyTuple_SetItem(args, 0, pystr);
921+
922+
PyObject* kwargs = PyDict_New();
923+
for (auto it = keywords.begin(); it != keywords.end(); ++it) {
924+
PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str()));
925+
}
926+
927+
PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_set_yscale, args, kwargs);
928+
929+
if(!res) throw std::runtime_error("Call to set_yscale() failed.");
930+
931+
Py_DECREF(args);
932+
Py_DECREF(kwargs);
933+
Py_DECREF(res);
934+
}
935+
886936
template< typename Numeric>
887937
bool hist(const std::vector<Numeric>& y, long bins=10,std::string color="b",
888938
double alpha=1.0, bool cumulative=false)

0 commit comments

Comments
 (0)
0