Commit fb65067d authored by René Fritze's avatar René Fritze Committed by René Fritze

[vis] cleanup MPL animation code a little

parent 05c36229
......@@ -3,7 +3,7 @@
# License: BSD 2-Clause License (
import numpy as np
from ipywidgets import HTML, HBox
from matplotlib import pyplot
import matplotlib.pyplot as plt
from pymor.core.config import config
from pymor.discretizers.builtin.gui.matplotlib import MatplotlibPatchAxes, Matplotlib1DAxes
......@@ -81,27 +81,20 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
self.vmins = (min(np.min(u) for u in U),) * len(U)
self.vmaxs = (max(np.max(u) for u in U),) * len(U)
import matplotlib.pyplot as plt
rows = int(np.ceil(len(U) / columns))
self.figure = figure = plt.figure()
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)
plots.append(MatplotlibPatchAxes(U=u, ax=ax, figure=figure, grid=grid, bounding_box=bounding_box, vmin=vmin, vmax=vmax,
codim=codim, colorbar=separate_colorbars or i == len(U)-1))
if legend:
# plt.tight_layout()
if not separate_colorbars:
if hasattr(plots[0], 'p'):
figure.colorbar(plots[0].p, ax=axes)
def set(self, U, ind):
if rescale_colorbars:
if separate_colorbars:
......@@ -130,6 +123,8 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
def __repr__(self):
return '\n\n'.join(repr(a) for a in self.args)
# otherwise the subplot displays twice
return concat_display(*[p.html for p in plot.plots])
return plot
......@@ -46,29 +46,24 @@ class MatplotlibPatchAxes:
if colorbar:
figure.colorbar(self.p, ax=ax)
delay_between_frames = 500 # ms
# TODO blit=True
delay_between_frames = 200 # ms
self.anim = animation.FuncAnimation(figure, self.set,
frames=U, interval=delay_between_frames,
# 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
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:
elif self.reference_element is triangle:
p.set_array(np.tile(U, 2))
p.set_clim(self.vmin, self.vmax)
return (p,)
self.p.set_array(np.tile(U, 2))
self.p.set_clim(self.vmin, self.vmax)
return (self.p,)
class Matplotlib1DAxes:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment