From 26577e8284ae50e2df123a3b256cf4ab7d6fc53f Mon Sep 17 00:00:00 2001 From: Matt Daley Date: Tue, 28 Apr 2020 16:15:08 +0100 Subject: [PATCH 1/3] Additional settings for plot_surface. --- matplotlibcpp.h | 66 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 12 deletions(-) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index b83d8f0..ed0555b 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -241,6 +241,40 @@ struct _interpreter { } // end namespace detail + struct SettingValue { + int type; + bool boolValue; + string stringValue; + float floatValue; + int intValue; + + public: + static const int String = 0; + static const int Bool = 1; + static const int Float = 2; + static const int Int = 3; + + SettingValue(const bool value) { + this->boolValue = value; + this->type = SettingValue::Bool; + } + + SettingValue(string value) { + this->stringValue = value; + this->type = SettingValue::String; + } + + SettingValue(float value) { + this->floatValue = value; + this->type = SettingValue::Float; + } + + SettingValue(int value) { + this->intValue = value; + this->type = SettingValue::Int; + } + }; + /// Select the backend /// /// **NOTE:** This must be called before the first plot command to have @@ -426,8 +460,8 @@ template void plot_surface(const std::vector<::std::vector> &x, const std::vector<::std::vector> &y, const std::vector<::std::vector> &z, - const std::map &keywords = - std::map()) + const std::map &keywords = + std::map()) { // We lazily load the modules here the first time this function is called // because I'm not sure that we can assume "matplotlib installed" implies @@ -466,18 +500,26 @@ void plot_surface(const std::vector<::std::vector> &x, // Build up the kw args. PyObject *kwargs = PyDict_New(); - PyDict_SetItemString(kwargs, "rstride", PyInt_FromLong(1)); - PyDict_SetItemString(kwargs, "cstride", PyInt_FromLong(1)); - - PyObject *python_colormap_coolwarm = PyObject_GetAttrString( - detail::_interpreter::get().s_python_colormap, "coolwarm"); - - PyDict_SetItemString(kwargs, "cmap", python_colormap_coolwarm); - for (std::map::const_iterator it = keywords.begin(); + for (std::map::const_iterator it = keywords.begin(); it != keywords.end(); ++it) { - PyDict_SetItemString(kwargs, it->first.c_str(), - PyString_FromString(it->second.c_str())); + PyObject *key = PyString_FromString(it->first.c_str()); + SettingValue value = it->second; + + switch (value.type) { + case SettingValue::String: + PyDict_SetItem(kwargs, key, PyString_FromString(value.stringValue.c_str())); + break; + case SettingValue::Float: + PyDict_SetItem(kwargs, key, PyFloat_FromDouble(value.floatValue)); + break; + case SettingValue::Int: + PyDict_SetItem(kwargs, key, PyInt_FromLong(value.intValue)); + break; + case SettingValue::Bool: + PyDict_SetItem(kwargs, key, PyBool_FromLong(value.boolValue)); + break; + } } From 45eb4aafabc608c0476b2349affce23e3c4c92c5 Mon Sep 17 00:00:00 2001 From: Matt Daley Date: Tue, 28 Apr 2020 17:00:13 +0100 Subject: [PATCH 2/3] Changed string to std::string in a few places. --- matplotlibcpp.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/matplotlibcpp.h b/matplotlibcpp.h index ed0555b..b4898da 100644 --- a/matplotlibcpp.h +++ b/matplotlibcpp.h @@ -244,7 +244,7 @@ struct _interpreter { struct SettingValue { int type; bool boolValue; - string stringValue; + std::string stringValue; float floatValue; int intValue; @@ -259,7 +259,7 @@ struct _interpreter { this->type = SettingValue::Bool; } - SettingValue(string value) { + SettingValue(std::string value) { this->stringValue = value; this->type = SettingValue::String; } From 13e6ba50c72d39b2c7ab5078d5d6caf9a5d020f9 Mon Sep 17 00:00:00 2001 From: Matt Daley Date: Tue, 28 Apr 2020 17:05:44 +0100 Subject: [PATCH 3/3] Some additions to .gitignore. --- .gitignore | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.gitignore b/.gitignore index 1c4a1b0..07c90bb 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,13 @@ # vim temp files *.sw* + +# clion +.idea/ + +# cmake +CmakeCache.txt +CMakeFiles/ +cmake-build-debug/ +cmake_install.cmake +