|
1 | 1 | #pragma once
|
2 | 2 | /*****************************************************************
|
3 |
| - Python headers must be included before any system headers, since |
4 |
| - they define _POSIX_C_SOURCE |
| 3 | + Python headers must be included before any system headers, since |
| 4 | + they define _POSIX_C_SOURCE |
5 | 5 | ******************************************************************/
|
6 | 6 | #include <Python.h>
|
7 | 7 |
|
@@ -2685,28 +2685,31 @@ inline void pause(Numeric interval) {
|
2685 | 2685 | Py_DECREF(res);
|
2686 | 2686 | }
|
2687 | 2687 |
|
2688 |
| -inline void save(const std::string& filename, const int dpi = 0) { |
2689 |
| - detail::_interpreter::get(); |
2690 |
| - |
| 2688 | +inline void savefig(const std::string& filename, |
| 2689 | + const std::map<std::string, std::string>& keywords = {}) { |
2691 | 2690 | PyObject* pyfilename = PyString_FromString(filename.c_str());
|
2692 | 2691 |
|
2693 | 2692 | PyObject* args = PyTuple_New(1);
|
2694 | 2693 | PyTuple_SetItem(args, 0, pyfilename);
|
2695 | 2694 |
|
2696 | 2695 | PyObject* kwargs = PyDict_New();
|
2697 |
| - |
2698 |
| - if (dpi > 0) { |
2699 |
| - PyDict_SetItemString(kwargs, "dpi", PyLong_FromLong(dpi)); |
| 2696 | + for (auto it = keywords.begin(); it != keywords.end(); ++it) { |
| 2697 | + PyDict_SetItemString(kwargs, it->first.c_str(), PyUnicode_FromString(it->second.c_str())); |
2700 | 2698 | }
|
2701 | 2699 |
|
2702 | 2700 | PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_save, args, kwargs);
|
2703 |
| - if (!res) throw std::runtime_error("Call to save() failed."); |
| 2701 | + if (!res) throw std::runtime_error("Call to savefig() failed."); |
2704 | 2702 |
|
2705 |
| - Py_DECREF(args); |
2706 | 2703 | Py_DECREF(kwargs);
|
| 2704 | + Py_DECREF(args); |
2707 | 2705 | Py_DECREF(res);
|
2708 | 2706 | }
|
2709 | 2707 |
|
| 2708 | +inline void save(const std::string& filename) { |
| 2709 | + std::cerr << "matplotlibcpp::save is deprecated, use savefig instead\n"; |
| 2710 | + matplotlibcpp::savefig(filename); |
| 2711 | +} |
| 2712 | + |
2710 | 2713 | inline void rcparams(const std::map<std::string, std::string>& keywords = {}) {
|
2711 | 2714 | detail::_interpreter::get();
|
2712 | 2715 | PyObject* args = PyTuple_New(0);
|
|
0 commit comments