Skip to content

Commit a4ffc57

Browse files
author
MamoruSobue
committed
added statistics/errorbar
1 parent 042bea7 commit a4ffc57

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

gallery/statistics/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
add_demo(hist hist.cpp)
2+
add_demo(errorbar errorbar.cpp)
23

34
add_custom_target(statitics
4-
DEPENDS hist
5+
DEPENDS hist errorbar
56
COMMAND hist
7+
COMMAND errorbar
68
COMMENT "running hist"
79
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
810
)

gallery/statistics/errorbar.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// example from https://matplotlib.org/stable/gallery/statistics/errorbar.html
2+
3+
#include <pybind11/embed.h>
4+
#include <pybind11/stl.h>
5+
6+
#include <matplotlibcpp17/pyplot.h>
7+
8+
#include <xtensor/xrandom.hpp>
9+
10+
#include <random>
11+
12+
namespace py = pybind11;
13+
using namespace py::literals;
14+
using namespace std;
15+
using namespace matplotlibcpp17;
16+
17+
int main() {
18+
py::scoped_interpreter guard{};
19+
auto plt = pyplot::import();
20+
auto x_ = xt::arange(0.1, 4.0, 0.5);
21+
auto y_ = xt::exp(-x_);
22+
vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end());
23+
24+
auto [fig, ax] = plt.subplots();
25+
ax.errorbar(Args(x, y), Kwargs("xerr"_a = 0.2, "yerr"_a = 0.4));
26+
#if USE_GUI
27+
plt.show();
28+
#else
29+
plt.savefig(Args("erorrbar.png"));
30+
#endif
31+
}

0 commit comments

Comments
 (0)