Skip to content
Open
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
39 changes: 19 additions & 20 deletions matplotlibcpp.h
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,16 +21,15 @@

# ifdef WITH_OPENCV
# include <opencv2/opencv.hpp>
# endif // WITH_OPENCV

/*
* A bunch of constants were removed in OpenCV 4 in favour of enum classes, so
* define the ones we need here.
*/
# if CV_MAJOR_VERSION > 3
# define CV_BGR2RGB cv::COLOR_BGR2RGB
# define CV_BGRA2RGBA cv::COLOR_BGRA2RGBA
# endif
# if CV_MAJOR_VERSION > 3
# define CV_BGR2RGB cv::COLOR_BGR2RGB
# define CV_BGRA2RGBA cv::COLOR_BGRA2RGBA
# endif
# endif // WITH_OPENCV
#endif // WITHOUT_NUMPY

#if PY_MAJOR_VERSION >= 3
Expand DownExpand Up@@ -328,7 +327,7 @@ inline bool annotate(std::string annotation, double x, double y)

if(res) Py_DECREF(res);

return res;
return bool(res);
}

namespace detail {
Expand DownExpand Up@@ -358,7 +357,7 @@ template <> struct select_npy_type<unsigned long long> { const static NPY_TYPES
template<typename Numeric>
PyObject* get_array(const std::vector<Numeric>& v)
{
npy_intp vsize = v.size();
npy_intp vsize = static_cast<npy_intp>(v.size());
NPY_TYPES type = select_npy_type<Numeric>::type;
if (type == NPY_NOTYPE) {
size_t memsize = v.size()*sizeof(double);
Expand DownExpand Up@@ -415,9 +414,9 @@ PyObject* get_array(const std::vector<Numeric>& v)
// sometimes, for labels and such, we need string arrays
inline PyObject * get_array(const std::vector<std::string>& strings)
{
PyObject* list = PyList_New(strings.size());
PyObject* list = PyList_New(static_cast<Py_ssize_t>(strings.size()));
for (std::size_t i = 0; i < strings.size(); ++i) {
PyList_SetItem(list, i, PyString_FromString(strings[i].c_str()));
PyList_SetItem(list, static_cast<Py_ssize_t>(i), PyString_FromString(strings[i].c_str()));
}
return list;
}
Expand DownExpand Up@@ -467,7 +466,7 @@ bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const st
Py_DECREF(kwargs);
if(res) Py_DECREF(res);

return res;
return bool(res);
}

// TODO - it should be possible to make this work by implementing
Expand DownExpand Up@@ -1325,7 +1324,7 @@ inline bool subplots_adjust(const std::map<std::string, double>& keywords = {})
Py_DECREF(kwargs);
if(res) Py_DECREF(res);

return res;
return bool(res);
}

template< typename Numeric>
Expand DownExpand Up@@ -1376,7 +1375,7 @@ bool plot(const std::vector<NumericX>& x, const std::vector<NumericY>& y, const
Py_DECREF(plot_args);
if(res) Py_DECREF(res);

return res;
return bool(res);
}

template <typename NumericX, typename NumericY, typename NumericZ>
Expand DownExpand Up@@ -1810,7 +1809,7 @@ template<typename Numeric>
bool plot(const std::vector<Numeric>& y, const std::string& format = "")
{
std::vector<Numeric> x(y.size());
for(size_t i=0; i<x.size(); ++i) x.at(i) = i;
for(size_t i=0; i<x.size(); ++i) x.at(i) = static_cast<Numeric>(i);
return plot(x,y,format);
}

Expand DownExpand Up@@ -1912,7 +1911,7 @@ inline bool fignum_exists(long number)
PyObject *res = PyObject_CallObject(detail::_interpreter::get().s_python_function_fignum_exists, args);
if(!res) throw std::runtime_error("Call to fignum_exists() failed.");

bool ret = PyObject_IsTrue(res);
bool ret = bool(PyObject_IsTrue(res));
Py_DECREF(res);
Py_DECREF(args);

Expand DownExpand Up@@ -2075,7 +2074,7 @@ inline std::array<double, 2> xlim()

PyObject* left = PyTuple_GetItem(res,0);
PyObject* right = PyTuple_GetItem(res,1);
return { PyFloat_AsDouble(left), PyFloat_AsDouble(right) };
return { {PyFloat_AsDouble(left), PyFloat_AsDouble(right)} };
}


Expand All@@ -2090,7 +2089,7 @@ inline std::array<double, 2> ylim()

PyObject* left = PyTuple_GetItem(res,0);
PyObject* right = PyTuple_GetItem(res,1);
return { PyFloat_AsDouble(left), PyFloat_AsDouble(right) };
return { {PyFloat_AsDouble(left), PyFloat_AsDouble(right)} };
}

template<typename Numeric>
Expand DownExpand Up@@ -2722,11 +2721,11 @@ inline std::vector<std::array<double, 2>> ginput(const int numClicks = 1, const
Py_DECREF(args);
if (!res) throw std::runtime_error("Call to ginput() failed.");

const size_t len = PyList_Size(res);
const size_t len = static_cast<const size_t>(PyList_Size(res));
std::vector<std::array<double, 2>> out;
out.reserve(len);
for (size_t i = 0; i < len; i++) {
PyObject *current = PyList_GetItem(res, i);
PyObject *current = PyList_GetItem(res, static_cast<Py_ssize_t>(i));
std::array<double, 2> position;
position[0] = PyFloat_AsDouble(PyTuple_GetItem(current, 0));
position[1] = PyFloat_AsDouble(PyTuple_GetItem(current, 1));
Expand DownExpand Up@@ -2944,7 +2943,7 @@ class Plot

PyObject* res = PyObject_CallObject(set_data_fct, plot_args);
if (res) Py_DECREF(res);
return res;
return bool(res);
}
return false;
}
Expand Down