Skip to content

Commit 3deedea

Browse files
committed
one plot window for std::vector and Eigen
1 parent 2faab93 commit 3deedea

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

examples/errorbar.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,34 @@ void get_data(Vector& x, Vector& y, Vector& err) {
1616
for (unsigned i = 0; i < n; ++i) {
1717
*(x.data() + i) = 1.0 * i / n;
1818
*(y.data() + i) = sin(2.0 * M_PI * i / n);
19-
*(err.data() + i) = exp(-2.0 * i / n);
19+
*(err.data() + i) = exp(-0.1 * i);
2020
}
2121
}
2222

2323
template <typename Vector>
2424
void plot(unsigned n) {
25+
// get the data
2526
Vector x(n), y(n), err(n);
2627
get_data(x, y, err);
2728

28-
plt::figure();
29+
// plot errorbar plot
2930
plt::errorbar(x, y, err);
30-
plt::show();
3131
}
3232

3333
int main() {
34+
// create figure
35+
plt::figure();
3436

37+
// plot with std::vector
3538
plot<std::vector<double>>(10);
3639

40+
// plot with Eigen::VectorXd, if specified
3741
#ifdef WITH_EIGEN
38-
#include <iostream>
39-
std::cout << "Hello!\n";
40-
plot<Eigen::VectorXd>(10);
42+
plot<Eigen::VectorXd>(13);
4143
#endif
4244

45+
// show plot
46+
plt::show();
47+
4348
return 0;
4449
}

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