Skip to content

Commit 85ba09b

Browse files
authored
Feat/return proxy (#27)
* (1) return ObjectWrapper (2) workaround for mplot3d Signed-off-by: soblin <hilo.soblin@gmail.com> * checked all samples working Signed-off-by: soblin <hilo.soblin@gmail.com> * adding const Signed-off-by: soblin <hilo.soblin@gmail.com> * adding const Signed-off-by: soblin <hilo.soblin@gmail.com> Signed-off-by: soblin <hilo.soblin@gmail.com>
1 parent d418287 commit 85ba09b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+635
-572
lines changed

gallery/artist_animation/animate_decay.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ int main() {
2727
auto [xmin, xmax] = ax.get_xlim();
2828
if (t >= xmax)
2929
ax.set_xlim(Args(xmin, 2 * xmax));
30-
py::object line =
31-
ax.plot(Args(ts, ys), Kwargs("color"_a = "blue", "lw"_a = 1));
32-
artist_list.append(line);
30+
auto line = ax.plot(Args(ts, ys), Kwargs("color"_a = "blue", "lw"_a = 1));
31+
artist_list.append(line.unwrap());
3332
}
3433
auto ani = ArtistAnimation(Args(fig.unwrap(), artist_list),
3534
Kwargs("interval"_a = 10));

gallery/artist_animation/random_walk.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// example from https://matplotlib.org/stable/gallery/animation/random_walk.html
22

3+
#include <matplotlibcpp17/axes.h>
34
#include <matplotlibcpp17/pyplot.h>
45
#include <matplotlibcpp17/animation.h>
6+
#include <matplotlibcpp17/mplot3d.h>
57

68
#include <xtensor/xrandom.hpp>
79
#include <xtensor/xbuilder.hpp>
@@ -32,21 +34,23 @@ int main() {
3234
}
3335
py::scoped_interpreter guard{};
3436
auto plt = matplotlibcpp17::pyplot::import();
37+
// this is required for "projection = 3d"
38+
matplotlibcpp17::mplot3d::import();
3539
auto fig = plt.figure();
3640
auto ax = fig.add_subplot(py::make_tuple(), Kwargs("projection"_a = "3d"));
3741
py::list artist_list;
3842
for (int j = 1; j <= num_steps; ++j) {
3943
for (int i = 0; i < M; ++i) {
40-
auto xs0 = xt::view(walks, i, 0, xt::range(1, j + 1));
41-
auto ys0 = xt::view(walks, i, 1, xt::range(1, j + 1));
42-
auto zs0 = xt::view(walks, i, 2, xt::range(1, j + 1));
44+
const auto xs0 = xt::view(walks, i, 0, xt::range(1, j + 1));
45+
const auto ys0 = xt::view(walks, i, 1, xt::range(1, j + 1));
46+
const auto zs0 = xt::view(walks, i, 2, xt::range(1, j + 1));
4347
// to vector
4448
vector<double> xs(xs0.begin(), xs0.end());
4549
vector<double> ys(ys0.begin(), ys0.end());
4650
vector<double> zs(zs0.begin(), zs0.end());
4751
ax.plot(Args(xs, ys, zs), Kwargs("color"_a = colors[i]));
4852
}
49-
artist_list.append(ax.get_lines());
53+
artist_list.append(ax.get_lines().unwrap());
5054
}
5155
auto ani = ArtistAnimation(Args(fig.unwrap(), artist_list),
5256
Kwargs("interval"_a = 100));

gallery/images_contours_and_fields/contourf_log.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ using mesh2D = vector<vector<double>>;
1919

2020
int main() {
2121
const int N = 100;
22-
auto x_ = xt::linspace(-3.0, 3.0, N);
23-
auto y_ = xt::linspace(-2.0, 2.0, N);
22+
const auto x_ = xt::linspace(-3.0, 3.0, N);
23+
const auto y_ = xt::linspace(-2.0, 2.0, N);
2424

25-
auto [X_, Y_] = xt::meshgrid(x_, y_);
26-
auto Z1_ = xt::exp(-xt::pow(X_, 2) - xt::pow(Y_, 2));
27-
auto Z2_ = xt::exp(-xt::pow(X_ * 10, 2) - xt::pow(Y_ * 10, 2));
25+
const auto [X_, Y_] = xt::meshgrid(x_, y_);
26+
const auto Z1_ = xt::exp(-xt::pow(X_, 2) - xt::pow(Y_, 2));
27+
const auto Z2_ = xt::exp(-xt::pow(X_ * 10, 2) - xt::pow(Y_ * 10, 2));
2828
xt::xarray<double> z_ = Z1_ + 50 * Z2_;
2929
// instead of x[:5, :5] = -1.0
3030
auto v = xt::view(z_, xt::range(_, 5), xt::range(_, 5));
@@ -45,14 +45,14 @@ int main() {
4545

4646
py::scoped_interpreter guard{};
4747
// to numpy array
48-
auto Xpy = py::array(py::cast(std::move(X)));
49-
auto Ypy = py::array(py::cast(std::move(Y)));
50-
auto zpy = py::array(py::cast(std::move(z)));
48+
const auto Xpy = py::array(py::cast(std::move(X)));
49+
const auto Ypy = py::array(py::cast(std::move(Y)));
50+
const auto zpy = py::array(py::cast(std::move(z)));
5151
auto plt = pyplot::import();
5252
auto [fig, ax] = plt.subplots();
5353
auto cs = ax.contourf(Args(Xpy, Ypy, zpy),
5454
Kwargs("locator"_a = ticker::LogLocator().unwrap(),
5555
"cmap"_a = cm::PuBu_r));
56-
fig.colorbar(Args(cs));
56+
fig.colorbar(Args(cs.unwrap()));
5757
plt.show();
5858
}

gallery/images_contours_and_fields/image_demo.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ using mesh2D = vector<vector<double>>;
1919
int main() {
2020
const double delta = 0.025;
2121
const auto x = xt::arange<double>(-3.0, 3.0, delta);
22-
auto [X_, Y_] = xt::meshgrid(x, x);
23-
auto Z1_ = xt::exp(-xt::pow(X_, 2) - xt::pow(Y_, 2));
24-
auto Z2_ = xt::exp(-xt::pow(X_ - 1, 2) - xt::pow(Y_ - 1, 2));
25-
auto Z_ = (Z1_ - Z2_) * 2.0;
22+
const auto [X_, Y_] = xt::meshgrid(x, x);
23+
const auto Z1_ = xt::exp(-xt::pow(X_, 2) - xt::pow(Y_, 2));
24+
const auto Z2_ = xt::exp(-xt::pow(X_ - 1, 2) - xt::pow(Y_ - 1, 2));
25+
const auto Z_ = (Z1_ - Z2_) * 2.0;
2626

2727
// to vector
2828
vector<double> X(X_.begin(), X_.end()), Y(Y_.begin(), Y_.end()),
@@ -42,7 +42,7 @@ int main() {
4242
auto [fig, ax] = plt.subplots();
4343
const double vmax = *max_element(Z_.begin(), Z_.end()),
4444
vmin = *min_element(Z_.begin(), Z_.end());
45-
auto Zpy = py::array(py::cast(std::move(Z2D)));
45+
const auto Zpy = py::array(py::cast(std::move(Z2D)));
4646
ax.imshow(Args(Zpy), Kwargs("interpolation"_a = "bilinear",
4747
"cmap"_a = cm::RdYlGn, "origin"_a = "lower",
4848
"extent"_a = py::make_tuple(-3, 3, -3, 3),

gallery/images_contours_and_fields/quiver_demo.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ using namespace std;
1414
using namespace matplotlibcpp17;
1515

1616
int main1() {
17-
auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.2),
18-
xt::arange<double>(0.0, 2 * M_PI, 0.2));
19-
auto U0 = xt::cos(X0);
20-
auto V0 = xt::sin(Y0);
17+
const auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.2),
18+
xt::arange<double>(0.0, 2 * M_PI, 0.2));
19+
const auto U0 = xt::cos(X0);
20+
const auto V0 = xt::sin(Y0);
2121
// to vector
2222
vector<double> X(X0.begin(), X0.end()), Y(Y0.begin(), Y0.end()),
2323
U(U0.begin(), U0.end()), V(V0.begin(), V0.end());
@@ -38,10 +38,10 @@ int main1() {
3838
}
3939

4040
int main2() {
41-
auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.6),
42-
xt::arange<double>(0.0, 2 * M_PI, 0.6));
43-
auto U0 = xt::cos(X0);
44-
auto V0 = xt::sin(Y0);
41+
const auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.6),
42+
xt::arange<double>(0.0, 2 * M_PI, 0.6));
43+
const auto U0 = xt::cos(X0);
44+
const auto V0 = xt::sin(Y0);
4545
// to vector
4646
vector<double> X(X0.begin(), X0.end()), Y(Y0.begin(), Y0.end()),
4747
U(U0.begin(), U0.end()), V(V0.begin(), V0.end());
@@ -65,11 +65,11 @@ int main2() {
6565
}
6666

6767
int main3() {
68-
auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.2),
69-
xt::arange<double>(0.0, 2 * M_PI, 0.2));
70-
auto U0 = xt::cos(X0);
71-
auto V0 = xt::sin(Y0);
72-
auto M0 = xt::hypot(U0, V0);
68+
const auto [X0, Y0] = xt::meshgrid(xt::arange<double>(0.0, 2 * M_PI, 0.2),
69+
xt::arange<double>(0.0, 2 * M_PI, 0.2));
70+
const auto U0 = xt::cos(X0);
71+
const auto V0 = xt::sin(Y0);
72+
const auto M0 = xt::hypot(U0, V0);
7373
vector<double> X(X0.begin(), X0.end()), Y(Y0.begin(), Y0.end()),
7474
U(U0.begin(), U0.end()), V(V0.begin(), V0.end()), M(M0.begin(), M0.end());
7575

gallery/lines_bars_and_markers/bar_label_demo.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ using namespace std;
1111
using namespace matplotlibcpp17;
1212

1313
int main1() {
14-
vector<int> menMeans = {20, 35, 30, 35, -27};
15-
vector<int> womenMeans = {25, 32, 34, 20, -25};
16-
vector<int> menStd = {2, 3, 4, 1, 2};
17-
vector<int> womenStd = {3, 5, 2, 3, 3};
18-
vector<int> ind = {0, 1, 2, 3, 4}; // the x locations for the groups
14+
const vector<int> menMeans = {20, 35, 30, 35, -27};
15+
const vector<int> womenMeans = {25, 32, 34, 20, -25};
16+
const vector<int> menStd = {2, 3, 4, 1, 2};
17+
const vector<int> womenStd = {3, 5, 2, 3, 3};
18+
const vector<int> ind = {0, 1, 2, 3, 4}; // the x locations for the groups
1919
const double width =
2020
0.35; // the width of the bars: can also be len(x) sequence
2121
auto plt = matplotlibcpp17::pyplot::import();
@@ -44,12 +44,12 @@ int main1() {
4444
}
4545

4646
int main2() {
47-
vector<string> people = {"Tom", "Dick", "Harry", "Slim", "Jim"};
48-
vector<int> y_pos = {0, 1, 2, 3, 4};
49-
vector<double> performance = {10.00367304, 10.42750809, 10.09280011,
50-
8.66745522, 12.77785333};
51-
vector<double> error = {0.70633485, 0.24791576, 0.15788335, 0.69769852,
52-
0.71995667};
47+
const vector<string> people = {"Tom", "Dick", "Harry", "Slim", "Jim"};
48+
const vector<int> y_pos = {0, 1, 2, 3, 4};
49+
const vector<double> performance = {10.00367304, 10.42750809, 10.09280011,
50+
8.66745522, 12.77785333};
51+
const vector<double> error = {0.70633485, 0.24791576, 0.15788335, 0.69769852,
52+
0.71995667};
5353
auto plt = matplotlibcpp17::pyplot::import();
5454
auto [fig, ax] = plt.subplots();
5555
auto hbars = ax.barh(Args(y_pos, performance),
@@ -71,12 +71,12 @@ int main2() {
7171
}
7272

7373
int main3() {
74-
vector<string> people = {"Tom", "Dick", "Harry", "Slim", "Jim"};
75-
vector<int> y_pos = {0, 1, 2, 3, 4};
76-
vector<double> performance = {10.00367304, 10.42750809, 10.09280011,
77-
8.66745522, 12.77785333};
78-
vector<double> error = {0.70633485, 0.24791576, 0.15788335, 0.69769852,
79-
0.71995667};
74+
const vector<string> people = {"Tom", "Dick", "Harry", "Slim", "Jim"};
75+
const vector<int> y_pos = {0, 1, 2, 3, 4};
76+
const vector<double> performance = {10.00367304, 10.42750809, 10.09280011,
77+
8.66745522, 12.77785333};
78+
const vector<double> error = {0.70633485, 0.24791576, 0.15788335, 0.69769852,
79+
0.71995667};
8080
auto plt = matplotlibcpp17::pyplot::import();
8181
auto [fig, ax] = plt.subplots();
8282
auto hbars = ax.barh(Args(y_pos, performance),

gallery/lines_bars_and_markers/errorbar_limits_simple.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ int main() {
1515
py::scoped_interpreter guard{};
1616
auto plt = pyplot::import();
1717
auto fig = plt.figure();
18-
auto x_ = xt::arange(0.0, 10.0, 1.0);
19-
auto y_ = 2.5 * xt::sin(x_ / 20 * M_PI);
20-
auto y1_ = y_ + 1.0, y2_ = y_ + 2.0, y3_ = y_ + 3.0;
21-
auto yerr_ = xt::linspace(0.05, 0.2, 10);
22-
vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end()),
18+
const auto x_ = xt::arange(0.0, 10.0, 1.0);
19+
const auto y_ = 2.5 * xt::sin(x_ / 20 * M_PI);
20+
const auto y1_ = y_ + 1.0, y2_ = y_ + 2.0, y3_ = y_ + 3.0;
21+
const auto yerr_ = xt::linspace(0.05, 0.2, 10);
22+
const vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end()),
2323
yerr(yerr_.begin(), yerr_.end()), y3(y3_.begin(), y3_.end()),
2424
y2(y2_.begin(), y2_.end()), y1(y1_.begin(), y1_.end());
2525
plt.errorbar(Args(x, y3),

gallery/lines_bars_and_markers/errorbar_subsample.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ using namespace std;
1212
using namespace matplotlibcpp17;
1313

1414
int main() {
15-
auto x_ = xt::arange(0.1, 4.0, 0.1);
16-
auto y1_ = xt::exp(-1.0 * x_);
17-
auto y2_ = xt::exp(-0.5 * x_);
18-
auto y1err_ = 0.1 + 0.1 * xt::sqrt(x_);
19-
auto y2err_ = 0.1 + 0.1 * xt::sqrt(x_ / 2.0);
20-
vector<double> x(x_.begin(), x_.end()), y1(y1_.begin(), y1_.end()),
15+
const auto x_ = xt::arange(0.1, 4.0, 0.1);
16+
const auto y1_ = xt::exp(-1.0 * x_);
17+
const auto y2_ = xt::exp(-0.5 * x_);
18+
const auto y1err_ = 0.1 + 0.1 * xt::sqrt(x_);
19+
const auto y2err_ = 0.1 + 0.1 * xt::sqrt(x_ / 2.0);
20+
const vector<double> x(x_.begin(), x_.end()), y1(y1_.begin(), y1_.end()),
2121
y2(y2_.begin(), y2_.end()), y1err(y1err_.begin(), y1err_.end()),
2222
y2err(y2err_.begin(), y2err_.end());
2323

@@ -34,11 +34,14 @@ int main() {
3434
ax1.errorbar(Args(x, y1), Kwargs("yerr"_a = y1err, "errorevery"_a = 6));
3535
ax1.errorbar(Args(x, y2), Kwargs("yerr"_a = y2err, "errorevery"_a = 6));
3636

37+
// TODO: TypeError: '<' not supported between instances of 'tuple' and 'int'
38+
/*
3739
ax2.set_title(Args("second seris shifted by 3"));
3840
ax2.errorbar(Args(x, y1),
3941
Kwargs("yerr"_a = y1err, "errorevery"_a = py::make_tuple(0, 6)));
4042
ax2.errorbar(Args(x, y2),
4143
Kwargs("yerr"_a = y2err, "errorevery"_a = py::make_tuple(3, 6)));
44+
*/
4245

4346
fig.suptitle(Args("Errorbar subsampling"));
4447
#if USE_GUI

gallery/lines_bars_and_markers/fill.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ using namespace matplotlibcpp17;
1313
int main() {
1414
const double scale = 10;
1515
const xt::xarray<double> angles = {90.0, 210.0, 330.0};
16-
auto x0 = scale / sqrt(3.0) * xt::cos(angles / 360.0 * 2 * M_PI);
17-
auto y0 = scale / sqrt(3.0) * xt::sin(angles / 360.0 * 2 * M_PI);
18-
vector<double> x(x0.begin(), x0.end());
19-
vector<double> y(y0.begin(), y0.end());
16+
const auto x0 = scale / sqrt(3.0) * xt::cos(angles / 360.0 * 2 * M_PI);
17+
const auto y0 = scale / sqrt(3.0) * xt::sin(angles / 360.0 * 2 * M_PI);
18+
const vector<double> x(x0.begin(), x0.end());
19+
const vector<double> y(y0.begin(), y0.end());
2020

2121
py::scoped_interpreter guard{};
2222
auto plt = matplotlibcpp17::pyplot::import();

gallery/lines_bars_and_markers/fill_between_demo.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ using namespace std;
1414
using namespace matplotlibcpp17;
1515

1616
int main1() {
17-
auto x_ = xt::arange(0.0, 2.0, 0.01);
18-
auto y1_ = xt::sin(2 * M_PI * x_);
19-
auto y2_ = 0.8 * xt::sin(4 * M_PI * x_);
20-
vector<double> x(x_.begin(), x_.end()), y1(y1_.begin(), y1_.end()),
17+
const auto x_ = xt::arange(0.0, 2.0, 0.01);
18+
const auto y1_ = xt::sin(2 * M_PI * x_);
19+
const auto y2_ = 0.8 * xt::sin(4 * M_PI * x_);
20+
const vector<double> x(x_.begin(), x_.end()), y1(y1_.begin(), y1_.end()),
2121
y2(y2_.begin(), y2_.end());
2222

2323
auto plt = matplotlibcpp17::pyplot::import();
@@ -45,9 +45,9 @@ int main1() {
4545
int main2() {
4646
auto plt = matplotlibcpp17::pyplot::import();
4747

48-
vector<double> x = {0, 1, 2, 3};
49-
vector<double> y1 = {0.8, 0.8, 0.2, 0.2};
50-
vector<double> y2 = {0, 0, 1, 1};
48+
const vector<double> x = {0, 1, 2, 3};
49+
const vector<double> y1 = {0.8, 0.8, 0.2, 0.2};
50+
const vector<double> y2 = {0, 0, 1, 1};
5151
auto [fig, axs] = plt.subplots(2, 1, Kwargs("sharex"_a = true));
5252
auto ax1 = axs[0], ax2 = axs[1];
5353

@@ -85,8 +85,8 @@ int main3() {
8585
auto plt = matplotlibcpp17::pyplot::import();
8686
auto [fig, ax] = plt.subplots();
8787

88-
auto x0 = xt::arange(0.0, 4 * M_PI, 0.01);
89-
auto y0 = xt::sin(x0);
88+
const auto x0 = xt::arange(0.0, 4 * M_PI, 0.01);
89+
const auto y0 = xt::sin(x0);
9090
vector<double> x(x0.begin(), x0.end()), y(y0.begin(), y0.end());
9191
ax.plot(Args(x, y), Kwargs("color"_a = "black"));
9292
const double threshold = 0.75;
@@ -96,7 +96,7 @@ int main3() {
9696
ax.fill_between(Args(x, 0, 1),
9797
Kwargs("where"_a = where, "color"_a = "green",
9898
"alpha"_a = 0.5,
99-
"transform"_a = ax.get_xaxis_transform()));
99+
"transform"_a = ax.get_xaxis_transform().unwrap()));
100100
#if USE_GUI
101101
plt.show();
102102
#else

gallery/lines_bars_and_markers/fill_betweenx_demo.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ using namespace matplotlibcpp17;
1313

1414
int main1() {
1515
auto plt = matplotlibcpp17::pyplot::import();
16-
auto y_ = xt::arange(0.0, 2.0, 0.01);
17-
auto x1_ = xt::sin(2 * M_PI * y_);
18-
auto x2_ = 1.2 * xt::sin(4 * M_PI * y_);
19-
vector<double> y(y_.begin(), y_.end()), x1(x1_.begin(), x1_.end()),
16+
const auto y_ = xt::arange(0.0, 2.0, 0.01);
17+
const auto x1_ = xt::sin(2 * M_PI * y_);
18+
const auto x2_ = 1.2 * xt::sin(4 * M_PI * y_);
19+
const vector<double> y(y_.begin(), y_.end()), x1(x1_.begin(), x1_.end()),
2020
x2(x2_.begin(), x2_.end());
2121

2222
auto [fig, axes] = plt.subplots(

gallery/lines_bars_and_markers/scatter_hist.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ using namespace matplotlibcpp17;
1414

1515
int main() {
1616
int N = 1000;
17-
auto x_ = xt::random::randn<double>({N});
18-
auto y_ = xt::random::randn<double>({N});
19-
vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end());
17+
const auto x_ = xt::random::randn<double>({N});
18+
const auto y_ = xt::random::randn<double>({N});
19+
const vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end());
2020
py::scoped_interpreter guard{};
2121
auto plt = matplotlibcpp17::pyplot::import();
2222
// cell1
@@ -40,7 +40,8 @@ int main() {
4040
ax_histy.tick_params(Args(), Kwargs("axis"_a = "y", "labelleft"_a = false));
4141
ax.scatter(Args(x, y));
4242
const double binwidth = 0.25;
43-
auto xi = xt::amax(xt::fabs(x_), {0}), yi = xt::amax(xt::fabs(y_), {0});
43+
const auto xi = xt::amax(xt::fabs(x_), {0}),
44+
yi = xt::amax(xt::fabs(y_), {0});
4445
const double xymax = max(fabs(x_[xi]), fabs(y_[yi]));
4546
const double lim = (static_cast<int>(xymax / binwidth) + 1) * binwidth;
4647
auto bins_ = xt::arange(-lim, lim + binwidth, binwidth);
@@ -73,7 +74,8 @@ int main() {
7374
ax_histy.tick_params(Args(), Kwargs("axis"_a = "y", "labelleft"_a = false));
7475
ax.scatter(Args(x, y));
7576
const double binwidth = 0.25;
76-
auto xi = xt::amax(xt::fabs(x_), {0}), yi = xt::amax(xt::fabs(y_), {0});
77+
const auto xi = xt::amax(xt::fabs(x_), {0}),
78+
yi = xt::amax(xt::fabs(y_), {0});
7779
const double xymax = max(fabs(x_[xi]), fabs(y_[yi]));
7880
const double lim = (static_cast<int>(xymax / binwidth) + 1) * binwidth;
7981
auto bins_ = xt::arange(-lim, lim + binwidth, binwidth);

gallery/lines_bars_and_markers/scatter_symbol.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ using namespace matplotlibcpp17;
2323
int main() {
2424
py::scoped_interpreter guard{};
2525
auto plt = pyplot::import();
26-
vector<double> x = {0., 2., 4., 6., 8., 10., 12., 14., 16.,
27-
18., 20., 22., 24., 26., 28., 30., 32., 34.,
28-
36., 38., 40., 42., 44., 46., 48.};
29-
vector<double> y = {
26+
const vector<double> x = {0., 2., 4., 6., 8., 10., 12., 14., 16.,
27+
18., 20., 22., 24., 26., 28., 30., 32., 34.,
28+
36., 38., 40., 42., 44., 46., 48.};
29+
const vector<double> y = {
3030
21.01101912, 24.74481311, 27.34126659, 27.27298483, 44.26208785,
3131
41.14266853, 32.72670355, 35.63706738, 57.689303, 64.43917295,
3232
56.86145395, 65.85596686, 91.33222544, 89.93319308, 90.07761828,
3333
104.3101143, 105.86324421, 125.79378295, 127.67869682, 131.83987721,
3434
140.51644988, 140.79566887, 153.22398837, 169.06951457, 174.97156606};
35-
vector<double> s = {
35+
const vector<double> s = {
3636
736.2911849, 628.75670445, 664.90041181, 607.46030945, 884.4840139,
3737
774.0174507, 790.37543212, 1278.33411095, 588.75488929, 810.61127126,
3838
1126.45270023, 1278.31780809, 886.56768427, 769.13688434, 953.93522899,

0 commit comments

Comments
 (0)