Skip to main content
Homepage
Explore
Search or go to…
/
Sign in
Explore
Primary navigation
Project
M
matplotlibcpp17
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Package registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Collapse sidebar
Snippets
Groups
Projects
Show more breadcrumbs
HKHLR
matplotlibcpp17
Commits
99bcb0ce
This project is archived. Its data is
read-only
.
Commit
99bcb0ce
authored
Mar 9, 2022
by
soblin
Browse files
Options
Downloads
Patches
Plain Diff
TODO: LinearLocator
parent
831f1ec4
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
gallery/mplot3d/CMakeLists.txt
+3
-1
3 additions, 1 deletion
gallery/mplot3d/CMakeLists.txt
gallery/mplot3d/surface3d.cpp
+56
-0
56 additions, 0 deletions
gallery/mplot3d/surface3d.cpp
include/matplotlibcpp17/cm.h
+1
-3
1 addition, 3 deletions
include/matplotlibcpp17/cm.h
with
60 additions
and
4 deletions
gallery/mplot3d/CMakeLists.txt
+
3
−
1
View file @
99bcb0ce
...
...
@@ -3,14 +3,16 @@ add_demo(lorenz_attractor lorenz_attractor.cpp)
add_demo
(
contour3d contour3d.cpp
)
add_demo
(
subplot3d subplot3d.cpp
)
add_demo
(
errorbar3d errorbar3d.cpp
)
add_demo
(
surface3d surface3d
)
add_custom_target
(
mplot3d
DEPENDS lines3d lorenz_attractor contour3d subplot3d errorbar3d
DEPENDS lines3d lorenz_attractor contour3d subplot3d errorbar3d
surface3d
COMMAND lines3d
COMMAND lorenz_attractor
COMMAND contour3d
COMMAND subplot3d
COMMAND errorbar3d
COMMAND surface3d
COMMENT
"running mplot3d"
WORKING_DIRECTORY
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/../images"
)
This diff is collapsed.
Click to expand it.
gallery/mplot3d/surface3d.cpp
0 → 100644
+
56
−
0
View file @
99bcb0ce
// example from https://matplotlib.org/stable/gallery/mplot3d/surface3d.html
#include
<pybind11/embed.h>
#include
<pybind11/stl.h>
#include
<pybind11/numpy.h>
#include
<matplotlibcpp17/pyplot.h>
#include
<matplotlibcpp17/cm.h>
#include
<xtensor/xbuilder.hpp>
#include
<xtensor/xmath.hpp>
#include
<vector>
namespace
py
=
pybind11
;
using
namespace
py
::
literals
;
using
namespace
std
;
using
namespace
matplotlibcpp17
;
using
mesh2D
=
vector
<
vector
<
double
>>
;
int
main
()
{
py
::
scoped_interpreter
guard
{};
auto
plt
=
matplotlibcpp17
::
pyplot
::
import
();
auto
[
fig
,
ax
]
=
plt
.
subplots
(
Kwargs
(
"subplot_kw"
_a
=
py
::
dict
(
"projection"
_a
=
"3d"
)));
auto
xs
=
xt
::
arange
(
-
5.0
,
5.0
,
0.25
);
auto
[
X0
,
Y0
]
=
xt
::
meshgrid
(
xs
,
xs
);
auto
R0
=
xt
::
sqrt
(
xt
::
pow
(
X0
,
2
)
+
xt
::
pow
(
Y0
,
2
));
auto
Z0
=
xt
::
sin
(
R0
);
// to vector<vector>
const
int
sz
=
xs
.
shape
()[
0
];
mesh2D
X
(
sz
),
Y
(
sz
),
Z
(
sz
);
for
(
int
i
=
0
;
i
<
sz
;
++
i
)
{
X
[
i
].
resize
(
sz
);
Y
[
i
].
resize
(
sz
);
Z
[
i
].
resize
(
sz
);
for
(
int
j
=
0
;
j
<
sz
;
++
j
)
{
X
[
i
][
j
]
=
X0
(
i
,
j
);
Y
[
i
][
j
]
=
Y0
(
i
,
j
);
Z
[
i
][
j
]
=
Z0
(
i
,
j
);
}
}
// to numpy array (vector<vector> is converted to list of list)
auto
X_
=
py
::
array
(
py
::
cast
(
std
::
move
(
X
)));
auto
Y_
=
py
::
array
(
py
::
cast
(
std
::
move
(
Y
)));
auto
Z_
=
py
::
array
(
py
::
cast
(
std
::
move
(
Z
)));
auto
surf
=
ax
.
plot_surface
(
Args
(
X_
,
Y_
,
Z_
),
Kwargs
(
"rstride"
_a
=
1
,
"cstride"
_a
=
1
,
"linewidth"
_a
=
0
,
"antialiased"
_a
=
false
,
"cmap"
_a
=
cm
::
coolwarm
()));
ax
.
set_zlim
(
Args
(
-
1.01
,
1.01
));
fig
.
colorbar
(
Args
(
surf
),
Kwargs
(
"shrink"
_a
=
0.5
,
"aspect"
_a
=
5
));
plt
.
show
();
}
This diff is collapsed.
Click to expand it.
include/matplotlibcpp17/cm.h
+
1
−
3
View file @
99bcb0ce
/**
* @file cm.h
* @brief corresponding header for matplotlib.
animation
* @brief corresponding header for matplotlib.
cm
**/
#ifndef MATPLOTLIBCPP17_CM_H
...
...
@@ -8,8 +8,6 @@
#include
<pybind11/pybind11.h>
#include
<matplotlibcpp17/common.h>
namespace
matplotlibcpp17
::
cm
{
pybind11
::
object
coolwarm
()
{
...
...
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment