<commit_before># This file is part of the pyMOR project (http://www.pymor.org).
# Copyright Holders: <NAME>, <NAME>, <NAME>
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

''' This module provides a widget for displaying plots of
scalar data assigned to a 1D-Grid using :mod:`matplotlib`. This widget is not
intended to be used directly. Instead, use
:meth:`~pymor.gui.qt.visualize_matplotlib_1d` or
:class:`~pymor.gui.qt.Matplotlib1DVisualizer`.
'''

from __future__ import absolute_import, division, print_function

from itertools import izip

import numpy as np
from PySide.QtGui import QSizePolicy

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

from pymor.grids.referenceelements import line


class Matplotlib1DWidget(FigureCanvas):

    def __init__(self, parent, grid, count, vmin=None, vmax=None, legend=None, codim=1, dpi=100):
        assert grid.reference_element is line
        assert codim in (0, 1)

        self.figure = Figure(dpi=dpi)
        self.axes = self.figure.gca()
        self.axes.hold(True)
        lines = tuple()
        for _ in xrange(count):
            l, = self.axes.plot(grid.centers(codim), np.zeros_like(grid.centers(codim)))
            lines = lines + (l,)
        self.axes.set_ylim(vmin, vmax)
        if legend:
            self.axes.legend(legend)
        self.lines = lines

        super(Matplotlib1DWidget, self).__init__(self.figure)
        self.setParent(parent)
        self.setMinimumSize(300, 300)
        self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

    def set(self, U, ind):
        for line, u in izip(self.lines, U):
            line.set_ydata(u[ind])
        self.draw()<commit_msg>[gui] add MatplotlibPatchWidget<commit_after># This file is part of the pyMOR project (http://www.pymor.org).
# Copyright Holders: <NAME>, <NAME>, <NAME>
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

''' This module provides a widget for displaying plots of
scalar data assigned to a 1D-Grid using :mod:`matplotlib`. This widget is not
intended to be used directly. Instead, use
:meth:`~pymor.gui.qt.visualize_matplotlib_1d` or
:class:`~pymor.gui.qt.Matplotlib1DVisualizer`.
'''

from __future__ import absolute_import, division, print_function

from itertools import izip

import numpy as np
from PySide.QtGui import QSizePolicy

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure

from pymor.grids.constructions import flatten_grid
from pymor.grids.referenceelements import line, triangle, square


class Matplotlib1DWidget(FigureCanvas):

    def __init__(self, parent, grid, count, vmin=None, vmax=None, legend=None, codim=1, dpi=100):
        assert grid.reference_element is line
        assert codim in (0, 1)

        self.figure = Figure(dpi=dpi)
        self.axes = self.figure.gca()
        self.axes.hold(True)
        lines = tuple()
        for _ in xrange(count):
            l, = self.axes.plot(grid.centers(codim), np.zeros_like(grid.centers(codim)))
            lines = lines + (l,)
        self.axes.set_ylim(vmin, vmax)
        if legend:
            self.axes.legend(legend)
        self.lines = lines

        super(Matplotlib1DWidget, self).__init__(self.figure)
        self.setParent(parent)
        self.setMinimumSize(300, 300)
        self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

    def set(self, U, ind):
        for line, u in izip(self.lines, U):
            line.set_ydata(u[ind])
        self.draw()


class MatplotlibPatchWidget(FigureCanvas):

    def __init__(self, parent, grid, bounding_box=None, vmin=None, vmax=None, codim=2, dpi=100):
        assert grid.reference_element in (triangle, square)
        assert grid.dim == 2
        assert codim in (0, 2)

        self.figure = Figure(dpi=dpi)
        super(MatplotlibPatchWidget, self).__init__(self.figure)

        subentities, coordinates, entity_map = flatten_grid(grid)
        self.subentities = subentities if grid.reference_element is triangle \
            else np.vstack((subentities[:, 0:3], subentities[:, [2, 3, 0]]))
        self.coordinates = coordinates
        self.entity_map = entity_map
        self.reference_element = grid.reference_element
        self.vmin = vmin
        self.vmax = vmax
        self.codim = codim
        self.setParent(parent)
        self.setMinimumSize(300, 300)
        self.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding))

    def set(self, U):
        U = np.array(U)
        f = self.figure
        f.clear()
        a = f.gca()
        if self.codim == 2:
            p = a.tripcolor(self.coordinates[:, 0], self.coordinates[:, 1], self.subentities, U,
                            vmin=self.vmin, vmax=self.vmax, shading='flat')
        elif self.reference_element is triangle:
            p = a.tripcolor(self.coordinates[:, 0], self.coordinates[:, 1], self.subentities, facecolors=U,
                            vmin=self.vmin, vmax=self.vmax, shading='flat')
        else:
            p = a.tripcolor(self.coordinates[:, 0], self.coordinates[:, 1], self.subentities,
                            facecolors=np.tile(U, 2), vmin=self.vmin, vmax=self.vmax, shading='flat')

        self.figure.colorbar(p)
        self.draw()
{'fraction_non_alphanumeric': 0.11226188274459034, 'fraction_numerical': 0.012206399112261884, 'mean_word_length': 2.9882005899705013, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1179376', 'n_tokens_mistral': 1806, 'n_tokens_neox': 1730, 'n_words': 412}