Skip to content

Commit 44eabb9

Browse files
committed
update
1 parent d846bbb commit 44eabb9

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

matplotlibcpp.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -955,7 +955,21 @@ inline void imshow(void* ptr, const NPY_TYPES type, const int rows, const int co
955955
for (std::map<std::string, std::string>::const_iterator it = keywords.begin();
956956
it != keywords.end(); ++it) {
957957
if (it->first == "extent") {
958+
std::stringstream ss(it->second);
959+
double ext[4];
960+
int i = 0;
961+
while (ss.good()) {
962+
std::string substr;
963+
getline(ss, substr, ',');
964+
ext[i] = std::stod(substr);
965+
i++;
958966
}
967+
PyDict_SetItemString(kwargs, it->first.c_str(),
968+
Py_BuildValue("(dddd)", ext[0], ext[1], ext[2], ext[3]));
969+
} else {
970+
PyDict_SetItemString(kwargs, it->first.c_str(),
971+
PyUnicode_FromString(it->second.c_str()));
972+
}
959973
}
960974

961975
PyObject* res =
@@ -984,6 +998,11 @@ inline void imshow(const float* ptr, const int rows, const int columns, const in
984998
}
985999

9861000
inline void imshow(const double* ptr, const int rows, const int columns, const int colors,
1001+
const std::map<std::string, std::string>& keywords = {},
1002+
PyObject** out = nullptr) {
1003+
detail::imshow((void*)ptr, NPY_DOUBLE, rows, columns, colors, keywords, out);
1004+
}
1005+
9871006
#ifdef WITH_OPENCV
9881007
void imshow(const cv::Mat& image, const std::map<std::string, std::string>& keywords = {}) {
9891008
// Convert underlying type of matrix, if needed
@@ -2277,7 +2296,23 @@ inline void subplot(long nrows, long ncols, long plot_number) {
22772296
Py_DECREF(res);
22782297
}
22792298

2299+
inline void subplot(long plot_number) {
2300+
detail::_interpreter::get();
2301+
2302+
// construct positional args
2303+
PyObject* args = PyTuple_New(1);
2304+
// PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
2305+
// PyTuple_SetItem(args, 1, PyFloat_FromDouble(ncols));
2306+
PyTuple_SetItem(args, 0, PyInt_FromLong(plot_number));
2307+
2308+
PyObject* res =
2309+
PyObject_CallObject(detail::_interpreter::get().s_python_function_subplot, args);
22802310
if (!res) throw std::runtime_error("Call to subplot() failed.");
2311+
2312+
Py_DECREF(args);
2313+
Py_DECREF(res);
2314+
}
2315+
22812316
inline void subplot2grid(long nrows, long ncols, long rowid = 0, long colid = 0, long rowspan = 1,
22822317
long colspan = 1) {
22832318
detail::_interpreter::get();

0 commit comments

Comments
 (0)