File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ //
2
+ // g++ -std=c++20 -g -Wall -o span $(python-config --includes) span.cpp $(python-config --ldflags --embed)
3
+ //
4
+ #include " ../matplotlibcpp.h"
5
+
6
+ #include < span>
7
+
8
+ using namespace std ;
9
+ namespace plt = matplotlibcpp;
10
+
11
+ int main ()
12
+ {
13
+ // C-style arrays with multiple rows
14
+ time_t t[]={1 , 2 , 3 , 4 };
15
+ int data[]={
16
+ 3 , 1 , 4 , 5 ,
17
+ 5 , 4 , 1 , 3 ,
18
+ 3 , 3 , 3 , 3
19
+ };
20
+
21
+ size_t n=sizeof (t)/sizeof (decltype (t[0 ]));
22
+ size_t m=sizeof (data)/sizeof (decltype (data[0 ]));
23
+
24
+ // Use std::span to pass data chunk to plot(), without copying it.
25
+ // Unfortunately, plt::plot() makes an internal copy of both x and y
26
+ // before passing them to python.
27
+ for (size_t offset=0 ; offset<m; offset+=n)
28
+ plt::plot (t, std::span {data+offset, n}, " " );
29
+ plt::show ();
30
+
31
+ plt::detail::_interpreter::kill ();
32
+
33
+ return 0 ;
34
+ }
You can’t perform that action at this time.
0 commit comments