| 1663 | |
| 1664 | template<typename Numeric> |
| 1665 | inline void xticks(const std::vector<Numeric> &ticks, const std::vector<std::string> &labels = {}, const std::map<std::string, std::string>& keywords = {}) |
| 1666 | { |
| 1667 | assert(labels.size() == 0 || ticks.size() == labels.size()); |
| 1668 | |
| 1669 | detail::_interpreter::get(); |
| 1670 | |
| 1671 | // using numpy array |
| 1672 | PyObject* ticksarray = detail::get_array(ticks); |
| 1673 | |
| 1674 | PyObject* args; |
| 1675 | if(labels.size() == 0) { |
| 1676 | // construct positional args |
| 1677 | args = PyTuple_New(1); |
| 1678 | PyTuple_SetItem(args, 0, ticksarray); |
| 1679 | } else { |
| 1680 | // make tuple of tick labels |
| 1681 | PyObject* labelstuple = PyTuple_New(labels.size()); |
| 1682 | for (size_t i = 0; i < labels.size(); i++) |
| 1683 | PyTuple_SetItem(labelstuple, i, PyUnicode_FromString(labels[i].c_str())); |
| 1684 | |
| 1685 | // construct positional args |
| 1686 | args = PyTuple_New(2); |
| 1687 | PyTuple_SetItem(args, 0, ticksarray); |
| 1688 | PyTuple_SetItem(args, 1, labelstuple); |
| 1689 | } |
| 1690 | |
| 1691 | // construct keyword args |
| 1692 | PyObject* kwargs = PyDict_New(); |
| 1693 | for(std::map<std::string, std::string>::const_iterator it = keywords.begin(); it != keywords.end(); ++it) |
| 1694 | { |
| 1695 | PyDict_SetItemString(kwargs, it->first.c_str(), PyString_FromString(it->second.c_str())); |
| 1696 | } |
| 1697 | |
| 1698 | PyObject* res = PyObject_Call(detail::_interpreter::get().s_python_function_xticks, args, kwargs); |
| 1699 | |
| 1700 | Py_DECREF(args); |
| 1701 | Py_DECREF(kwargs); |
| 1702 | if(!res) throw std::runtime_error("Call to xticks() failed"); |
| 1703 | |
| 1704 | Py_DECREF(res); |
| 1705 | } |
| 1706 | |
| 1707 | template<typename Numeric> |
| 1708 | inline void xticks(const std::vector<Numeric> &ticks, const std::map<std::string, std::string>& keywords) |