Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2bf4f26

Browse files
williamleonglava
authored andcommitted
Fix lava#221 and lava#225
1 parent d1b7c72 commit 2bf4f26

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

matplotlibcpp.h

+16-11
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,12 @@ struct _interpreter {
176176
wchar_t const *dummy_args[] = {L"Python", NULL}; // const is needed because literals must not be modified
177177
wchar_t const **argv = dummy_args;
178178
int argc = sizeof(dummy_args)/sizeof(dummy_args[0])-1;
179+
180+
#if PY_MAJOR_VERSION >= 3
179181
PySys_SetArgv(argc, const_cast<wchar_t **>(argv));
182+
#else
183+
PySys_SetArgv(argc, (char **)(argv));
184+
#endif
180185

181186
#ifndef WITHOUT_NUMPY
182187
import_numpy(); // initialize numpy C-API
@@ -362,7 +367,7 @@ PyObject* get_array(const std::vector<Numeric>& v)
362367
PyArray_UpdateFlags(reinterpret_cast<PyArrayObject*>(varray), NPY_ARRAY_OWNDATA);
363368
return varray;
364369
}
365-
370+
366371
PyObject* varray = PyArray_SimpleNewFromData(1, &vsize, type, (void*)(v.data()));
367372
return varray;
368373
}
@@ -429,7 +434,7 @@ PyObject* get_listlist(const std::vector<std::vector<Numeric>>& ll)
429434
} // namespace detail
430435

431436
/// Plot a line through the given x and y data points..
432-
///
437+
///
433438
/// See: https://matplotlib.org/3.2.1/api/_as_gen/matplotlib.pyplot.plot.html
434439
template<typename Numeric>
435440
bool plot(const std::vector<Numeric> &x, const std::vector<Numeric> &y, const std::map<std::string, std::string>& keywords)
@@ -587,9 +592,9 @@ void plot3(const std::vector<Numeric> &x,
587592
{
588593
detail::_interpreter::get();
589594

590-
// Same as with plot_surface: We lazily load the modules here the first time
591-
// this function is called because I'm not sure that we can assume "matplotlib
592-
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
595+
// Same as with plot_surface: We lazily load the modules here the first time
596+
// this function is called because I'm not sure that we can assume "matplotlib
597+
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
593598
// want to require it for people who don't need 3d plots.
594599
static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
595600
if (!mpl_toolkitsmod) {
@@ -1849,7 +1854,7 @@ inline void legend(const std::map<std::string, std::string>& keywords)
18491854
if(!res) throw std::runtime_error("Call to legend() failed.");
18501855

18511856
Py_DECREF(kwargs);
1852-
Py_DECREF(res);
1857+
Py_DECREF(res);
18531858
}
18541859

18551860
template<typename Numeric>
@@ -2089,7 +2094,7 @@ inline void tick_params(const std::map<std::string, std::string>& keywords, cons
20892094
inline void subplot(long nrows, long ncols, long plot_number)
20902095
{
20912096
detail::_interpreter::get();
2092-
2097+
20932098
// construct positional args
20942099
PyObject* args = PyTuple_New(3);
20952100
PyTuple_SetItem(args, 0, PyFloat_FromDouble(nrows));
@@ -2154,7 +2159,7 @@ inline void title(const std::string &titlestr, const std::map<std::string, std::
21542159
inline void suptitle(const std::string &suptitlestr, const std::map<std::string, std::string> &keywords = {})
21552160
{
21562161
detail::_interpreter::get();
2157-
2162+
21582163
PyObject* pysuptitlestr = PyString_FromString(suptitlestr.c_str());
21592164
PyObject* args = PyTuple_New(1);
21602165
PyTuple_SetItem(args, 0, pysuptitlestr);
@@ -2286,9 +2291,9 @@ inline void set_zlabel(const std::string &str, const std::map<std::string, std::
22862291
{
22872292
detail::_interpreter::get();
22882293

2289-
// Same as with plot_surface: We lazily load the modules here the first time
2290-
// this function is called because I'm not sure that we can assume "matplotlib
2291-
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
2294+
// Same as with plot_surface: We lazily load the modules here the first time
2295+
// this function is called because I'm not sure that we can assume "matplotlib
2296+
// installed" implies "mpl_toolkits installed" on all platforms, and we don't
22922297
// want to require it for people who don't need 3d plots.
22932298
static PyObject *mpl_toolkitsmod = nullptr, *axis3dmod = nullptr;
22942299
if (!mpl_toolkitsmod) {

0 commit comments

Comments
 (0)