Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,13 @@

# vim temp files
*.sw*

# clion
.idea/

# cmake
CmakeCache.txt
CMakeFiles/
cmake-build-debug/
cmake_install.cmake

66 changes: 54 additions & 12 deletions matplotlibcpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,40 @@ struct _interpreter {

} // end namespace detail

struct SettingValue {
int type;
bool boolValue;
std::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(std::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
Expand Down Expand Up @@ -426,8 +460,8 @@ template <typename Numeric>
void plot_surface(const std::vector<::std::vector<Numeric>> &x,
const std::vector<::std::vector<Numeric>> &y,
const std::vector<::std::vector<Numeric>> &z,
const std::map<std::string, std::string> &keywords =
std::map<std::string, std::string>())
const std::map<std::string, SettingValue> &keywords =
std::map<std::string, SettingValue>())
{
// 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
Expand Down Expand Up @@ -466,18 +500,26 @@ void plot_surface(const std::vector<::std::vector<Numeric>> &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<std::string, std::string>::const_iterator it = keywords.begin();
for (std::map<std::string, SettingValue>::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;
}
}


Expand Down