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
1a13ea31
Commit
1a13ea31
authored
Jul 17, 2020
by
René Fritze
Committed by
René Fritze
Jul 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[vis] Quick&Dirty transfer of MPL animation to 1D
parent
fb65067d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
20 deletions
+38
-20
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
+23
-15
src/pymor/discretizers/builtin/gui/matplotlib.py
src/pymor/discretizers/builtin/gui/matplotlib.py
+15
-5
No files found.
src/pymor/discretizers/builtin/gui/jupyter/matplotlib.py
View file @
1a13ea31
...
...
@@ -10,6 +10,20 @@ from pymor.discretizers.builtin.gui.matplotlib import MatplotlibPatchAxes, Matpl
from
pymor.vectorarrays.interface
import
VectorArray
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
)
def
visualize_patch
(
grid
,
U
,
bounding_box
=
([
0
,
0
],
[
1
,
1
]),
codim
=
2
,
title
=
None
,
legend
=
None
,
separate_colorbars
=
False
,
rescale_colorbars
=
False
,
columns
=
2
):
"""Visualize scalar data associated to a two-dimensional |Grid| as a patch plot.
...
...
@@ -95,6 +109,7 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
if
legend
:
ax
.
set_title
(
legend
[
i
])
def
set
(
self
,
U
,
ind
):
if
rescale_colorbars
:
if
separate_colorbars
:
...
...
@@ -110,18 +125,11 @@ 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
)
# otherwise the subplot displays twice
plt
.
close
(
plot
.
figure
)
return
concat_display
(
*
[
p
.
html
for
p
in
plot
.
plots
])
def
__repr__
(
self
):
return
'
\n\n
'
.
join
(
repr
(
a
)
for
a
in
self
.
args
)
return
plot
# otherwise the subplot displays twice
plt
.
close
(
plot
.
figure
)
...
...
@@ -129,7 +137,6 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
return
plot
return
None
def
visualize_matplotlib_1d
(
grid
,
U
,
codim
=
1
,
title
=
None
,
legend
=
None
,
separate_plots
=
False
,
separate_axes
=
False
,
columns
=
2
):
...
...
@@ -198,7 +205,7 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_
self
.
plots
=
[]
axes
=
[]
for
i
,
(
vmin
,
vmax
)
in
enumerate
(
zip
(
self
.
vmins
,
self
.
vmaxs
)):
for
i
,
(
vmin
,
vmax
,
u
)
in
enumerate
(
zip
(
self
.
vmins
,
self
.
vmaxs
,
U
)):
if
separate_plots
:
ax
=
self
.
figure
.
add_subplot
(
rows
,
columns
,
i
+
1
)
else
:
...
...
@@ -207,7 +214,7 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_
count
=
1
if
not
separate_plots
:
count
=
len
(
U
[
0
])
self
.
plots
.
append
(
Matplotlib1DAxes
(
ax
,
grid
,
count
,
vmin
=
vmin
,
vmax
=
vmax
,
self
.
plots
.
append
(
Matplotlib1DAxes
(
u
,
ax
,
self
.
figure
,
grid
,
count
,
vmin
=
vmin
,
vmax
=
vmax
,
codim
=
codim
))
if
legend
:
ax
.
set_title
(
legend
[
i
])
...
...
@@ -222,4 +229,5 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_
self
.
plots
[
0
].
set
(
U
,
vmin
=
self
.
vmins
[
0
],
vmax
=
self
.
vmaxs
[
0
])
plot
=
Plot
()
plot
.
set
(
U
[
0
])
if
len
(
U
[
0
])
>
1
:
\ No newline at end of file
src/pymor/discretizers/builtin/gui/matplotlib.py
View file @
1a13ea31
...
...
@@ -68,14 +68,16 @@ class MatplotlibPatchAxes:
class
Matplotlib1DAxes
:
def
__init__
(
self
,
axes
,
grid
,
count
,
vmin
=
None
,
vmax
=
None
,
codim
=
1
):
def
__init__
(
self
,
U
,
axes
,
figure
,
grid
,
count
,
vmin
=
None
,
vmax
=
None
,
codim
=
1
):
assert
isinstance
(
grid
,
OnedGrid
)
assert
codim
in
(
0
,
1
)
self
.
codim
=
codim
self
.
grid
=
grid
self
.
vmin
=
vmin
self
.
vmax
=
vmax
self
.
count
=
count
self
.
U
=
U
centers
=
grid
.
centers
(
1
)
if
grid
.
identify_left_right
:
...
...
@@ -96,15 +98,21 @@ class Matplotlib1DAxes:
self
.
axes
=
axes
self
.
lines
=
lines
delay_between_frames
=
200
# ms
self
.
anim
=
animation
.
FuncAnimation
(
figure
,
self
.
set
,
frames
=
U
,
interval
=
delay_between_frames
,
blit
=
True
)
# generating the HTML instance outside this class causes the plot display to fail
self
.
html
=
HTML
(
self
.
anim
.
to_jshtml
())
def
set
(
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
for
i
in
range
(
self
.
count
):
u
=
np
.
array
(
U
[
i
])
if
self
.
codim
==
1
:
if
self
.
periodic
:
self
.
lines
[
i
].
set_ydata
(
np
.
concatenate
((
u
,
[
u
[
0
]])))
self
.
lines
[
i
].
set_ydata
(
np
.
concatenate
((
u
,
[
self
.
U
[
0
]])))
else
:
self
.
lines
[
i
].
set_ydata
(
u
)
else
:
...
...
@@ -112,6 +120,8 @@ class Matplotlib1DAxes:
pad
=
(
self
.
vmax
-
self
.
vmin
)
*
0.1
self
.
axes
.
set_ylim
(
self
.
vmin
-
pad
,
self
.
vmax
+
pad
)
return
self
.
lines
if
config
.
HAVE_QT
and
config
.
HAVE_MATPLOTLIB
:
...
...
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