Commit c20bf6f2 authored by Hendrik Kleikamp's avatar Hendrik Kleikamp Committed by René Fritze

[gui] enable separate axes for subplots

parent f6fdfc91
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"U = m.solution_space.empty()\n", "U = m.solution_space.empty()\n",
"for mu in parameter_space.sample_uniformly(10):\n", "for mu in parameter_space.sample_uniformly(10):\n",
" U.append(m.solve(mu))\n", " U.append(m.solve(mu))\n",
"m.visualize(U, title='Solution for diffusionl in [0.1, 1]', separate_plots=False)" "m.visualize(U, title='Solution for diffusionl in [0.1, 1]', separate_plots=True, separate_axes=False)"
] ]
} }
], ],
......
...@@ -125,7 +125,35 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None, ...@@ -125,7 +125,35 @@ def visualize_patch(grid, U, bounding_box=([0, 0], [1, 1]), codim=2, title=None,
return None return None
def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_plots=False, columns=2): def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_plots=False, separate_axes=False, columns=2):
"""Visualize scalar data associated to a one-dimensional |Grid| as a plot.
The grid's |ReferenceElement| must be the line. The data can either
be attached to the subintervals or vertices of the grid.
Parameters
----------
grid
The underlying |Grid|.
U
|VectorArray| of the data to visualize. If `len(U) > 1`, the data is visualized
as a time series of plots. Alternatively, a tuple of |VectorArrays| can be
provided, in which case several plots are made into the same axes. The
lengths of all arrays have to agree.
codim
The codimension of the entities the data in `U` is attached to (either 0 or 1).
title
Title of the plot.
legend
Description of the data that is plotted. Most useful if `U` is a tuple in which
case `legend` has to be a tuple of strings of the same length.
separate_plots
If `True`, use subplots to visualize multiple |VectorArrays|.
separate_axes
If `True`, use separate axes for each subplot.
column
Number of columns the subplots are organized in.
"""
assert isinstance(U, VectorArray) \ assert isinstance(U, VectorArray) \
or (isinstance(U, tuple) or (isinstance(U, tuple)
and all(isinstance(u, VectorArray) for u in U) and all(isinstance(u, VectorArray) for u in U)
...@@ -146,11 +174,15 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_ ...@@ -146,11 +174,15 @@ def visualize_matplotlib_1d(grid, U, codim=1, title=None, legend=None, separate_
def __init__(self): def __init__(self):
if separate_plots: if separate_plots:
self.vmins = tuple(np.min(u) for u in U[0]) if separate_axes:
self.vmaxs = tuple(np.max(u) for u in U[0]) self.vmins = tuple(np.min(u) for u in U[0])
self.vmaxs = tuple(np.max(u) for u in U[0])
else:
self.vmins = (min(np.min(u) for u in U),) * len(U[0])
self.vmaxs = (max(np.max(u) for u in U),) * len(U[0])
else: else:
self.vmins = (min(np.min(u) for u in U),) self.vmins = (min(np.min(u) for u in U[0]),)
self.vmaxs = (max(np.max(u) for u in U),) self.vmaxs = (max(np.max(u) for u in U[0]),)
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
# Copyright 2013-2020 pyMOR developers and contributors. All rights reserved. # Copyright 2013-2020 pyMOR developers and contributors. All rights reserved.
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause) # License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
""" This module provides a widgets for displaying plots of """ This module provides widgets for displaying plots of
scalar data assigned to one- and two-dimensional grids using scalar data assigned to one- and two-dimensional grids using
:mod:`matplotlib`. This widget is not intended to be used directly. :mod:`matplotlib`. These widgets are not intended to be used directly.
""" """
import numpy as np import numpy as np
...@@ -101,7 +101,8 @@ class Matplotlib1DAxes: ...@@ -101,7 +101,8 @@ class Matplotlib1DAxes:
else: else:
self.lines[i].set_ydata(np.repeat(u, 2)) self.lines[i].set_ydata(np.repeat(u, 2))
self.axes.set_ylim(self.vmin, self.vmax) pad = (self.vmax - self.vmin) * 0.1
self.axes.set_ylim(self.vmin - pad, self.vmax + pad)
if config.HAVE_QT and config.HAVE_MATPLOTLIB: if config.HAVE_QT and config.HAVE_MATPLOTLIB:
......
...@@ -118,7 +118,7 @@ class OnedVisualizer(BasicObject): ...@@ -118,7 +118,7 @@ class OnedVisualizer(BasicObject):
self.__auto_init(locals()) self.__auto_init(locals())
def visualize(self, U, m, title=None, legend=None, separate_plots=False, def visualize(self, U, m, title=None, legend=None, separate_plots=False,
block=None, filename=None, columns=2): separate_axes=False, block=None, filename=None, columns=2):
"""Visualize the provided data. """Visualize the provided data.
Parameters Parameters
...@@ -145,7 +145,7 @@ class OnedVisualizer(BasicObject): ...@@ -145,7 +145,7 @@ class OnedVisualizer(BasicObject):
if self.backend == 'jupyter': if self.backend == 'jupyter':
from pymor.discretizers.builtin.gui.jupyter.matplotlib import visualize_matplotlib_1d from pymor.discretizers.builtin.gui.jupyter.matplotlib import visualize_matplotlib_1d
return visualize_matplotlib_1d(self.grid, U, codim=self.codim, title=title, legend=legend, return visualize_matplotlib_1d(self.grid, U, codim=self.codim, title=title, legend=legend,
separate_plots=separate_plots, columns=columns) separate_plots=separate_plots, separate_axes=separate_axes, columns=columns)
else: else:
block = self.block if block is None else block block = self.block if block is None else block
from pymor.discretizers.builtin.gui.qt import visualize_matplotlib_1d from pymor.discretizers.builtin.gui.qt import visualize_matplotlib_1d
......
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