Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
P
pymor
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Insights
Issue
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
pyMOR
pymor
Commits
3328aa65
Commit
3328aa65
authored
Jul 14, 2020
by
René Fritze
Committed by
René Fritze
Jul 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[vis] working example of mpl animation
parent
db88a217
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
8 deletions
+29
-8
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
+16
-2
src/pymor/discretizers/builtin/gui/matplotlib.py
src/pymor/discretizers/builtin/gui/matplotlib.py
+13
-6
No files found.
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
View file @
3328aa65
...
...
@@ -3,6 +3,7 @@
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
import
numpy
as
np
from
ipywidgets
import
HTML
,
HBox
from
matplotlib
import
pyplot
from
pymor.core.config
import
config
from
pymor.discretizers.builtin.gui.matplotlib
import
MatplotlibPatchAxes
,
Matplotlib1DAxes
...
...
@@ -88,6 +89,7 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
self
.
plots
=
plots
=
[]
axes
=
[]
for
i
,
(
vmin
,
vmax
,
u
)
in
enumerate
(
zip
(
self
.
vmins
,
self
.
vmaxs
,
U
)):
# we do not use figures.subplots since conditionally returns an axes array or a single object
ax
=
figure
.
add_subplot
(
rows
,
columns
,
i
+
1
)
axes
.
append
(
ax
)
plots
.
append
(
MatplotlibPatchAxes
(
U
=
u
,
ax
=
ax
,
figure
=
figure
,
grid
=
grid
,
bounding_box
=
bounding_box
,
vmin
=
vmin
,
vmax
=
vmax
,
...
...
@@ -95,7 +97,7 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
if
legend
:
ax
.
set_title
(
legend
[
i
])
plt
.
tight_layout
()
#
plt.tight_layout()
if
not
separate_colorbars
:
if
hasattr
(
plots
[
0
],
'p'
):
figure
.
colorbar
(
plots
[
0
].
p
,
ax
=
axes
)
...
...
@@ -115,8 +117,20 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
plot
=
Plot
()
if
len
(
U
[
0
])
>
1
:
class
concat_display
(
object
):
"""Display HTML representation of multiple objects"""
template
=
"""<div style="float: left; padding: 10px;">{0}</div>"""
def
__init__
(
self
,
*
args
):
self
.
args
=
args
def
_repr_html_
(
self
):
return
'
\n
'
.
join
(
self
.
template
.
format
(
a
.
_repr_html_
())
for
a
in
self
.
args
)
def
__repr__
(
self
):
return
'
\n\n
'
.
join
(
repr
(
a
)
for
a
in
self
.
args
)
return
HBox
([
HTML
(
p
.
anim
.
to_jshtml
())
for
p
in
plot
.
plots
])
return
concat_display
(
*
[
p
.
html
for
p
in
plot
.
plots
])
return
plot
...
...
src/pymor/discretizers/builtin/gui/matplotlib.py
View file @
3328aa65
...
...
@@ -8,7 +8,8 @@ scalar data assigned to one- and two-dimensional grids using
"""
import
numpy
as
np
from
matplotlib
import
animation
from
IPython.core.display
import
display
,
HTML
from
matplotlib
import
animation
,
pyplot
from
pymor.core.config
import
config
from
pymor.discretizers.builtin.grids.constructions
import
flatten_grid
...
...
@@ -33,7 +34,7 @@ class MatplotlibPatchAxes:
self
.
vmax
=
vmax
self
.
codim
=
codim
self
.
U
=
U
a
=
ax
if
self
.
codim
==
2
:
self
.
p
=
ax
.
tripcolor
(
self
.
coordinates
[:,
0
],
self
.
coordinates
[:,
1
],
self
.
subentities
,
np
.
zeros
(
len
(
self
.
coordinates
)),
...
...
@@ -43,17 +44,23 @@ class MatplotlibPatchAxes:
facecolors
=
np
.
zeros
(
len
(
self
.
subentities
)),
vmin
=
self
.
vmin
,
vmax
=
self
.
vmax
,
shading
=
'flat'
)
if
colorbar
:
figure
.
colorbar
(
self
.
p
,
ax
=
a
)
delay_between_frames
=
200
# ms
figure
.
colorbar
(
self
.
p
,
ax
=
ax
)
delay_between_frames
=
500
# ms
# TODO blit=True
self
.
anim
=
animation
.
FuncAnimation
(
figure
,
self
.
animate
,
self
.
anim
=
animation
.
FuncAnimation
(
figure
,
self
.
set
,
frames
=
U
,
interval
=
delay_between_frames
,
blit
=
False
)
# generating the HTML instance outside this class causes the plot display to fail
self
.
html
=
HTML
(
self
.
anim
.
to_jshtml
())
# otherwise the subplot displays twice
pyplot
.
close
(
figure
)
def
animate
(
self
,
U
,
vmin
=
None
,
vmax
=
None
):
def
set
(
self
,
U
,
vmin
=
None
,
vmax
=
None
):
self
.
vmin
=
self
.
vmin
if
vmin
is
None
else
vmin
self
.
vmax
=
self
.
vmax
if
vmax
is
None
else
vmax
p
=
self
.
p
if
self
.
codim
==
2
:
p
.
set_array
(
U
)
elif
self
.
reference_element
is
triangle
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment