<commit_before>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import six
from collections import defaultdict, OrderedDict

from matplotlib.backends.qt4_compat import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas  # noqa
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar  # noqa
from matplotlib.figure import Figure
from matplotlib.cm import datad
from matplotlib import colors
import numpy as np

_CMAPS = datad.keys()
_CMAPS.sort()


class PlotWidget(QtGui.QMainWindow):
    """
    Top level container for one control widget and one data view widget
    """
    def __init__(self, parent=None, embed=True):
        """
        init doc-string

        Parameters
        ----------
        parent : QWidget
            parent widget


        embed : bool
            if widget should be embeddable in another widget (if true)
            or a stand-alone window (false)
        """
        # explictily call up the stack
        # TODO sort out qt5 super rules
        QtGui.QMainWindow.__init__(self, parent)
        # set flag is this should be widget or a main window
        if embed:
            self.setWindowFlags(QtCore.Qt.Widget)

        # dummy figure size in inches
        width = height = 12
        # create the Figure object
        self._fig = Figure(figsize=(width, height))
        # create the canvas (and connect it to the figure)
        self._canvas = FigureCanvas(self.fig, parent=self)
        # set the canvas to fill available space
        self._canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)
        self._canvas.updateGeometry()

        # set the central widget to be the canvas
        self.setCentralWidget(self._canvas)

        # create the control box
        control_box_name = 'controls'
        self._config = QtGui.QDockWidget(control_box_name)
        self._ctl_widget = ControlContainer(self.ctrl_box_2)

    @property
    def fig(self):
        """
        The `Figure` object for this widget.
        """
        return self._fig

    @property
    def control(self):
        return self._ctl_widget


class AbstractDataView(object):
    """
    AbstractDataView class docstring.  Defaults to a single matplotlib axes
    """
    def __init__(self, fig, ax1=None, data_dict=None, cmap=None, norm=None):
        """
        init docstring

        Parameters
        ----------
        data_dict : Dictionary
            Dictionary of data sets
        fig :
        ax1 :
        data_dict :
        cmap :
        norm :
        """
        # stash the figure
        self._fig = fig
        if ax1 is not None:
            # stash the main axes
            self._ax1 = ax1
        else:
            # create the matplotlib axes
            self._ax1 = self._fig.add_subplot(1, 1, 1)
            self._ax1.set_aspect('equal')

        # save the colormap
        if cmap is None:
            self._cmap = _CMAPS[0]
        else:
            self._cmap = cmap
        # save the normalization
        if norm is None:
            self._norm = colors.Normalize(0, 1, clip=True)
        else:
            self._norm = norm

        if data_dict is not None:
            self._data = data_dict
        else:
            self._data = OrderedDict()

    def update_colormap(self, new_cmap):
        """
        Update the color map used to display the image
        """
        self._cmap = new_cmap

    def replot(self):
        """
        Do nothing in the abstract base class. Needs to be implemented
        in the concrete classes
        """
        pass


class AbstractDataView1D(AbstractDataView):
    """
    AbstractDataView1D class docstring.  Defaults to a single matplotlib axes
    """
    def __init__(self, fig, data_dict, cmap=None, norm=None):
        """
        __init__ docstring__

        Parameters
        ----------
        """
        # pass the init up
        AbstractDataView.__init__(self, fig=fig, data_dict=data_dict,
                                  cmap=cmap, norm=norm)

    def add_data(self, x, y, lbl):
        """
        add data with the name 'lbl'.  Will overwrite data if<commit_msg>DOC: Raise an exception if the abstract method replot is not overriden by a concrete class<commit_after>from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
import six
from collections import defaultdict, OrderedDict

from matplotlib.backends.qt4_compat import QtGui, QtCore
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas  # noqa
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QT as NavigationToolbar  # noqa
from matplotlib.figure import Figure
from matplotlib.cm import datad
from matplotlib import colors
import numpy as np

_CMAPS = datad.keys()
_CMAPS.sort()


class PlotWidget(QtGui.QMainWindow):
    """
    Top level container for one control widget and one data view widget
    """
    def __init__(self, parent=None, embed=True):
        """
        init doc-string

        Parameters
        ----------
        parent : QWidget
            parent widget


        embed : bool
            if widget should be embeddable in another widget (if true)
            or a stand-alone window (false)
        """
        # explictily call up the stack
        # TODO sort out qt5 super rules
        QtGui.QMainWindow.__init__(self, parent)
        # set flag is this should be widget or a main window
        if embed:
            self.setWindowFlags(QtCore.Qt.Widget)

        # dummy figure size in inches
        width = height = 12
        # create the Figure object
        self._fig = Figure(figsize=(width, height))
        # create the canvas (and connect it to the figure)
        self._canvas = FigureCanvas(self.fig, parent=self)
        # set the canvas to fill available space
        self._canvas.setSizePolicy(QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)
        self._canvas.updateGeometry()

        # set the central widget to be the canvas
        self.setCentralWidget(self._canvas)

        # create the control box
        control_box_name = 'controls'
        self._config = QtGui.QDockWidget(control_box_name)
        self._ctl_widget = ControlContainer(self.ctrl_box_2)

    @property
    def fig(self):
        """
        The `Figure` object for this widget.
        """
        return self._fig

    @property
    def control(self):
        return self._ctl_widget


class AbstractDataView(object):
    """
    AbstractDataView class docstring.  Defaults to a single matplotlib axes
    """
    def __init__(self, fig, ax1=None, data_dict=None, cmap=None, norm=None):
        """
        init docstring

        Parameters
        ----------
        data_dict : Dictionary
            Dictionary of data sets
        fig :
        ax1 :
        data_dict :
        cmap :
        norm :
        """
        # stash the figure
        self._fig = fig
        if ax1 is not None:
            # stash the main axes
            self._ax1 = ax1
        else:
            # create the matplotlib axes
            self._ax1 = self._fig.add_subplot(1, 1, 1)
            self._ax1.set_aspect('equal')

        # save the colormap
        if cmap is None:
            self._cmap = _CMAPS[0]
        else:
            self._cmap = cmap
        # save the normalization
        if norm is None:
            self._norm = colors.Normalize(0, 1, clip=True)
        else:
            self._norm = norm

        if data_dict is not None:
            self._data = data_dict
        else:
            self._data = OrderedDict()

    def update_colormap(self, new_cmap):
        """
        Update the color map used to display the image
        """
        self._cmap = new_cmap

    def replot(self):
        """
        Do nothing in the abstract base class. Needs to be implemented
        in the concrete classes
        """
        raise Exception("Must override the replot() method in the concrete base class")


class AbstractDataView1D(AbstractDataView):
    """
    AbstractDataView1D class docstring.  Defaults to a single matplotlib axes
    """
    def __init__(self, fig, data_dict, cmap=None, norm=None):
        """
        __init__ docstring__

        Parameters
        ----------
        """
        # pass the init up
        AbstractDataView.__init__(self, fig=fig, data_dict=data_dict,
                                  cmap=cmap, norm=norm)

    def add_data(self, x, y, lbl):
        """
        add data with the name 'lbl'.  Will overwrite data if
{'fraction_non_alphanumeric': 0.07730187814933577, 'fraction_numerical': 0.005267979844251031, 'mean_word_length': 1.9090606262491672, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6412916', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2365, 'n_words': 750}