Skip to content

Commit 3e3a8db

Browse files
committed
Merge branch 'develop'
2 parents 62ee0d3 + 673fbda commit 3e3a8db

File tree

24 files changed

+394
-38
lines changed

24 files changed

+394
-38
lines changed

.dir-locals.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
((c++-mode . ((mode . clang-format+))))

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v3.2.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-added-large-files
11+
12+
# CMake formatting
13+
- repo: https://github.com/cheshirekow/cmake-format-precommit
14+
rev: "v0.6.13"
15+
hooks:
16+
- id: cmake-format
17+
additional_dependencies: [pyyaml]
18+
types: [file]
19+
files: (\.cmake|CMakeLists.txt)(.in)?$

CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ endif()
3535
# gallery
3636
if(NOT DEFINED USE_GUI)
3737
set(USE_GUI 1)
38-
message(STATUS "USE_GUI = ON")
38+
message(STATUS "set USE_GUI = ON")
3939
endif()
4040
if(NOT DEFINED ADD_DEMO)
4141
set(ADD_DEMO 1)
42+
message(STATUS "set ADD_DEMO = ON")
4243
endif()
4344
if(USE_GUI)
4445
message(STATUS "USE_GUI = ON")
@@ -77,6 +78,7 @@ if(${ADD_DEMO})
7778
add_subdirectory(gallery/shapes_and_collections)
7879
add_subdirectory(gallery/artist_animation)
7980
add_subdirectory(gallery/mplot3d)
81+
add_subdirectory(gallery/scales)
8082
endif()
8183

8284
# test
@@ -127,7 +129,6 @@ set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")
127129
# create .deb
128130
include("${PROJECT_SOURCE_DIR}/cmake/package.cmake")
129131

130-
# uninstall target. actually it's just `xargs rm < install_manifest.txt`
131132
# https://gitlab.kitware.com/cmake/community/-/wikis/FAQ#can-i-do-make-uninstall-with-cmake
132133
if(NOT TARGET uninstall)
133134
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/cmake/uninstall.cmake.in"

gallery/artist_animation/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ add_demo(cla_pause cla_pause.cpp)
22
add_demo(animate_decay animate_decay.cpp)
33
add_demo(random_walk random_walk.cpp)
44

5-
add_custom_target(artist_animation
5+
add_custom_target(
6+
artist_animation
67
DEPENDS cla_pause animate_decay
78
COMMAND cla_pause
89
COMMAND animate_decay
910
COMMAND random_walk
1011
COMMENT "running artist_animation"
11-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
12-
)
12+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
add_demo(quiver_demo quiver_demo.cpp)
2+
add_demo(contourf_log contourf_log)
23

3-
add_custom_target(images_contours_and_fields
4-
DEPENDS quiver_demo
4+
add_custom_target(
5+
images_contours_and_fields
6+
DEPENDS quiver_demo contourf_log
57
COMMAND quiver_demo
6-
COMMENT "running quiver_demo"
7-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
8-
)
8+
COMMAND contourf_log
9+
COMMENT "running images_contours_and_fields"
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// example from
2+
// https://matplotlib.org/stable/gallery/images_contours_and_fields/contourf_log.html
3+
4+
#include <matplotlibcpp17/pyplot.h>
5+
#include <matplotlibcpp17/cm.h>
6+
#include <matplotlibcpp17/ticker.h>
7+
8+
#include <xtensor/xbuilder.hpp>
9+
#include <xtensor/xview.hpp>
10+
#include <xtensor/xmath.hpp>
11+
12+
#include <vector>
13+
14+
using namespace std;
15+
using namespace matplotlibcpp17;
16+
using namespace xt::placeholders;
17+
18+
using mesh2D = vector<vector<double>>;
19+
20+
int main() {
21+
const int N = 100;
22+
auto x_ = xt::linspace(-3.0, 3.0, N);
23+
auto y_ = xt::linspace(-2.0, 2.0, N);
24+
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));
28+
xt::xarray<double> z_ = Z1_ + 50 * Z2_;
29+
// instead of x[:5, :5] = -1.0
30+
auto v = xt::view(z_, xt::range(_, 5), xt::range(_, 5));
31+
v = 0.0;
32+
// to vector<vector>>
33+
const int xsz = x_.shape()[0], ysz = y_.shape()[0];
34+
mesh2D X(xsz), Y(xsz), z(xsz);
35+
for (int i = 0; i < xsz; ++i) {
36+
X[i].resize(ysz);
37+
Y[i].resize(ysz);
38+
z[i].resize(ysz);
39+
for (int j = 0; j < ysz; ++j) {
40+
X[i][j] = X_(i, j);
41+
Y[i][j] = Y_(i, j);
42+
z[i][j] = z_(i, j);
43+
}
44+
}
45+
46+
py::scoped_interpreter guard{};
47+
// 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)));
51+
auto plt = pyplot::import();
52+
auto [fig, ax] = plt.subplots();
53+
auto cs = ax.contourf(Args(Xpy, Ypy, zpy),
54+
Kwargs("locator"_a = ticker::LogLocator().unwrap(),
55+
"cmap"_a = cm::PuBu_r()));
56+
fig.colorbar(Args(cs));
57+
plt.show();
58+
}

gallery/lines_bars_and_markers/CMakeLists.txt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,21 @@ add_demo(scatter_with_legend scatter_with_legend.cpp)
88
add_demo(scatter_hist scatter_hist.cpp)
99
add_demo(errorbar_limits_simple errorbar_limits_simple.cpp)
1010
add_demo(errorbar_subsample errorbar_subsample.cpp)
11+
add_demo(step_demo step_demo.cpp)
1112

12-
add_custom_target(lines_bars_and_markers
13-
DEPENDS bar_label_demo fill simple_plot scatter_symbol fill_between_demo fill_betweenx_demo scatter_with_legend scatter_hist errorbar_limits_simple errorbar_subsample
13+
add_custom_target(
14+
lines_bars_and_markers
15+
DEPENDS bar_label_demo
16+
fill
17+
simple_plot
18+
scatter_symbol
19+
fill_between_demo
20+
fill_betweenx_demo
21+
scatter_with_legend
22+
scatter_hist
23+
errorbar_limits_simple
24+
errorbar_subsample
25+
step_demo
1426
COMMAND bar_label_demo
1527
COMMAND fill
1628
COMMAND simple_plot
@@ -21,6 +33,6 @@ add_custom_target(lines_bars_and_markers
2133
COMMAND scatter_hist
2234
COMMAND errorbar_limits_simple
2335
COMMAND errorbar_subsample
36+
COMMAND step_demo
2437
COMMENT "running lines_bars_and_markers"
25-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
26-
)
38+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// example from
2+
// https://matplotlib.org/stable/gallery/lines_bars_and_markers/step_demo.html
3+
4+
#include <matplotlibcpp17/pyplot.h>
5+
6+
#include <xtensor/xbuilder.hpp>
7+
#include <xtensor/xmath.hpp>
8+
9+
#include <vector>
10+
11+
using namespace std;
12+
using namespace matplotlibcpp17;
13+
14+
int main() {
15+
py::scoped_interpreter guard{};
16+
auto plt = pyplot::import();
17+
18+
auto x_ = xt::arange(14) * 1.0;
19+
auto y_ = xt::sin(x_ / 2.0);
20+
auto y1_ = y_ + 1.0, y2_ = y_ + 2.0;
21+
vector<double> x(x_.begin(), x_.end()), y(y_.begin(), y_.end()),
22+
y1(y1_.begin(), y1_.end()), y2(y2_.begin(), y2_.end());
23+
24+
plt.step(Args(x, y2), Kwargs("label"_a = "pre (default)"));
25+
plt.plot(Args(x, y2, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3));
26+
27+
plt.step(Args(x, y1), Kwargs("where"_a = "mid", "label"_a = "mid"));
28+
plt.plot(Args(x, y1, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3));
29+
30+
plt.step(Args(x, y), Kwargs("where"_a = "post", "label"_a = "post"));
31+
plt.plot(Args(x, y, "o--"), Kwargs("color"_a = "grey", "alpha"_a = 0.3));
32+
33+
plt.grid(Args(), Kwargs("axis"_a = "x", "color"_a = "0.95"));
34+
plt.legend(Args(), Kwargs("title"_a = "Parameter where:"));
35+
plt.title(Args("plt.step(where...)"));
36+
plt.show();
37+
}

gallery/mplot3d/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ add_demo(subplot3d subplot3d.cpp)
55
add_demo(errorbar3d errorbar3d.cpp)
66
add_demo(surface3d surface3d)
77

8-
add_custom_target(mplot3d
8+
add_custom_target(
9+
mplot3d
910
DEPENDS lines3d lorenz_attractor contour3d subplot3d errorbar3d surface3d
1011
COMMAND lines3d
1112
COMMAND lorenz_attractor
@@ -14,5 +15,4 @@ add_custom_target(mplot3d
1415
COMMAND errorbar3d
1516
COMMAND surface3d
1617
COMMENT "running mplot3d"
17-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
18-
)
18+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")

gallery/mplot3d/contour3d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// example https://matplotlib.org/stable/gallery/mplot3d/contour3d.html
22

33
#include <matplotlibcpp17/pyplot.h>
4+
#include <matplotlibcpp17/cm.h>
45

56
#include <xtensor/xbuilder.hpp>
67
#include <xtensor/xmath.hpp>
@@ -49,8 +50,7 @@ int main() {
4950
auto fig = plt.figure();
5051
auto ax = fig.add_subplot(Args(), Kwargs("projection"_a = "3d"));
5152
auto [X, Y, Z] = get_test_data(0.05);
52-
// TODO: cmap=cm.coolwarm
53-
ax.contour(Args(X, Y, Z));
53+
ax.contour(Args(X, Y, Z), Kwargs("cmap"_a = cm::coolwarm()));
5454
#if USE_GUI
5555
plt.show();
5656
#else

gallery/mplot3d/surface3d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ int main() {
4545
"linewidth"_a = 0, "antialiased"_a = false,
4646
"cmap"_a = cm::coolwarm()));
4747
ax.set_zlim(Args(-1.01, 1.01));
48+
// TODO
49+
// auto locator = ticker::LinearLocator(Args(10));
50+
// ax.zaxis.set_major_locator(Args(locator.unwrap()));
51+
// ax.zaxis.set_major_formatter(Args("{x:.02f}"));
4852
fig.colorbar(Args(surf), Kwargs("shrink"_a = 0.5, "aspect"_a = 5));
4953
plt.show();
5054
}

gallery/scales/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_demo(aspect_loglog aspect_loglog.cpp)
2+
3+
add_custom_target(
4+
scales
5+
DEPENDS aspect_loglog
6+
COMMAND aspect_loglog
7+
COMMENT "running scales"
8+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")

gallery/scales/aspect_loglog.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// example from https://matplotlib.org/stable/gallery/scales/aspect_loglog.html
2+
3+
#include <matplotlibcpp17/pyplot.h>
4+
#include <matplotlibcpp17/animation.h>
5+
6+
#include <vector>
7+
8+
using namespace std;
9+
using namespace matplotlibcpp17;
10+
11+
int main() {
12+
py::scoped_interpreter guard{};
13+
auto plt = pyplot::import();
14+
auto [fig, axs] = plt.subplots(1, 2);
15+
auto &ax1 = axs[0], ax2 = axs[1];
16+
ax1.set_xscale(Args("log"));
17+
ax1.set_yscale(Args("log"));
18+
ax1.set_xlim(Args(1e+1, 1e+3));
19+
ax1.set_ylim(Args(1e+2, 1e+3));
20+
ax1.set_aspect(Args(1));
21+
ax1.set_title(Args("adjustable = box"));
22+
23+
ax2.set_xscale(Args("log"));
24+
ax2.set_yscale(Args("log"));
25+
ax2.set_adjustable(Args("datalim"));
26+
ax2.plot(Args(vector<int>({1, 3, 10}), vector<int>({1, 9, 100}), "o-"));
27+
ax2.set_xlim(Args(1e-1, 1e+2));
28+
ax2.set_ylim(Args(1e-1, 1e+3));
29+
ax2.set_aspect(Args(1));
30+
ax2.set_title(Args("adjustable = datalim"));
31+
32+
plt.show();
33+
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
add_demo(patch_collection patch_collection.cpp)
22
add_demo(patches_circle_rectangle patches_circle_rectangle.cpp)
33

4-
add_custom_target(shapes_and_collections
4+
add_custom_target(
5+
shapes_and_collections
56
DEPENDS patch_collection patches_circle_rectangle
67
COMMAND patch_collection
78
COMMAND patches_circle_rectangle
89
COMMENT "running shapes_and_collections"
9-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
10-
)
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")

gallery/statistics/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
add_demo(hist hist.cpp)
22
add_demo(errorbar errorbar.cpp)
33

4-
add_custom_target(statitics
4+
add_custom_target(
5+
statitics
56
DEPENDS hist errorbar
67
COMMAND hist
78
COMMAND errorbar
89
COMMENT "running hist"
9-
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images"
10-
)
10+
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../images")

gallery/subplots_axes_and_figures/CMakeLists.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ add_demo(gridspec_multicolumn gridspec_multicolumn.cpp)
33
add_demo(multiple_figs_demo multiple_figs_demo.cpp)
44
add_demo(colorbar_placement colorbar_placement.cpp)
55
add_demo(subplots subplots.cpp)
6+
add_demo(two_scales two_scales.cpp)
67

7-
add_custom_target(subplots_axes_and_figures
8-
DEPENDS align_labels_demo gridspec_multicolumn multiple_figs_demo colorbar_placement
8+
add_custom_target(
9+
subplots_axes_and_figures
10+
DEPENDS align_labels_demo gridspec_multicolumn multiple_figs_demo
11+
colorbar_placement two_scales
912
COMMAND align_labels_demo
1013
COMMAND gridspec_multicolumn
1114
COMMAND multiple_figs_demo
1215
COMMAND colorbar_placement
16+
COMMAND two_scales
1317
COMMENT "subplots_axes_and_figures"
14-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
15-
)
18+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// example from
2+
// https://matplotlib.org/stable/gallery/subplots_axes_and_figures/two_scales.html
3+
4+
#include <matplotlibcpp17/pyplot.h>
5+
6+
#include <xtensor/xbuilder.hpp>
7+
#include <xtensor/xmath.hpp>
8+
9+
#include <vector>
10+
11+
using namespace std;
12+
using namespace matplotlibcpp17;
13+
14+
int main() {
15+
auto t_ = xt::arange(0.01, 10.0, 0.01);
16+
auto data1_ = xt::exp(t_);
17+
auto data2_ = xt::sin(2 * M_PI * t_);
18+
vector<double> t(t_.begin(), t_.end()), data1(data1_.begin(), data1_.end()),
19+
data2(data2_.begin(), data2_.end());
20+
21+
py::scoped_interpreter guard{};
22+
auto plt = pyplot::import();
23+
auto [fig, ax1] = plt.subplots();
24+
25+
auto color = "tab:red";
26+
ax1.set_xlabel(Args("time (s)"));
27+
ax1.set_ylabel(Args("exp"), Kwargs("color"_a = color));
28+
ax1.plot(Args(t, data1), Kwargs("color"_a = color));
29+
ax1.tick_params(Args(), Kwargs("axis"_a = "y", "labelcolor"_a = color));
30+
31+
auto ax2 =
32+
ax1.twinx(); // instantiate a second axes that shares the same x-axis
33+
34+
color = "tab:blue";
35+
ax2.set_ylabel(Args("sin"), Kwargs("color"_a = color));
36+
ax2.plot(Args(t, data2), Kwargs("color"_a = color));
37+
ax2.tick_params(Args(), Kwargs("axis"_a = "y", "labelcolor"_a = color));
38+
39+
fig.tight_layout();
40+
plt.show();
41+
}

hello_world/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ find_package(matplotlibcpp17 REQUIRED)
99

1010
add_executable(hello_world hello_world.cpp)
1111
target_include_directories(hello_world PUBLIC ${Python3_INCLUDE_DIRS})
12-
target_link_libraries(hello_world ${Python3_LIBRARIES} pybind11::embed matplotlibcpp17::matplotlibcpp17)
12+
target_link_libraries(hello_world ${Python3_LIBRARIES} pybind11::embed
13+
matplotlibcpp17::matplotlibcpp17)

0 commit comments

Comments
 (0)