Skip to content

Commit c5a2b1d

Browse files
committed
add loc and bbox_to_anchor support for legend
1 parent 377ac84 commit c5a2b1d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

matplotlibcpp.h

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,12 +1161,25 @@ inline void figure_size(size_t w, size_t h) {
11611161
Py_DECREF(res);
11621162
}
11631163

1164-
inline void legend() {
1164+
template <typename Vector = std::vector<double>>
1165+
inline void legend(const std::string &loc = "best",
1166+
const Vector &bbox_to_anchor = Vector()) {
11651167
detail::_interpreter::get();
11661168

1169+
PyObject *kwargs = PyDict_New();
1170+
PyDict_SetItemString(kwargs, "loc", PyString_FromString(loc.c_str()));
1171+
1172+
if (bbox_to_anchor.size() == 2 || bbox_to_anchor.size() == 4) {
1173+
PyObject *bbox = get_array(bbox_to_anchor);
1174+
PyDict_SetItemString(kwargs, "bbox_to_anchor", bbox);
1175+
}
1176+
11671177
PyObject *res =
1168-
PyObject_CallObject(detail::_interpreter::get().s_python_function_legend,
1169-
detail::_interpreter::get().s_python_empty_tuple);
1178+
PyObject_Call(detail::_interpreter::get().s_python_function_legend,
1179+
detail::_interpreter::get().s_python_empty_tuple, kwargs);
1180+
1181+
Py_DECREF(kwargs);
1182+
11701183
if (!res)
11711184
throw std::runtime_error("Call to legend() failed.");
11721185

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy