Exemplo n.º 1
0
    def __init__(self,
                 left_plotlist,
                 right_plotlist=None,
                 left_log=False,
                 right_log=False,
                 auto_update=True,
                 backend='qwt',
                 parent=None,
                 **kwargs):
        """Initialize the plotting backend, data and local setting

        :param left_plotlist: Codenames for the plots that should go on the
            left y-axis
        :type left_plotlist: iterable with strs
        :param right_plotlist: Codenames for the plots that should go in the
            right y-axis
        :type left_plotlist: iterable with strs
        :param left_log: Left y-axis should be log
        :type left_log: bool
        :param right_log: Right y-axis should be log
        :type right_log: bool
        :param auto_update: Whether all data actions should trigger an update
        :type auto_update: bool
        :param backend: The plotting backend to use. Current only option is
            'qwt'
        :type backend: str
        :param parent: If a GUI backend is used that needs to know the parent
            GUI object, then that should be supplied here
        :type parent: GUI object

        Kwargs:

        :param title: The title of the plot
        :type title: str
        :param xaxis_label: Label for the x axis
        :type xaxis_label: str
        :param yaxis_left_label: Label for the left y axis
        :type yaxis_left_label: str
        :param yaxis_right_label: Label for the right y axis
        :type yaxis_right_label: str
        :param left_labels: Labels for the plots on the left y-axis. If none
            are given the codenames will be used.
        :type left_labels: iterable with strs
        :param right_labels: Labels for the plots on the right y-axis. If none
            are given the codenames will be used.
        :type right_labels: iterable with strs
        :param legend: Position of the legend. Possible values are:
            'left', 'right', 'bottom', 'top'. If no argument is given, the
            legend will not be shown.
        :type legend: str
        :param left_colors: Colors for the left curves (see background_color
            for details)
        :type left_colors: iterable of strs
        :param right_colors: Colors for the right curves (see background_color
            for details)
        :type right_colors: iterable of strs
        :param left_thickness: Line thickness. Either an integer to apply for
            all left lines or a iterable of integers, one for each line.
        :type left_thickness: int or iterable of ints
        :param right_thickness: Line thickness. Either an integer to apply for
            all right lines or a iterable of integers, one for each line.
        :type right_thickness: int or iterable of ints
        :param background_color: The name in a str (as understood by
            QtGui.QColor(), see :ref:`colors-section` section for possible
            values) or a string with a hex value e.g. '#101010' that should
            be used as the background color.
        :type background_color: str
        """
        # Gather all plots
        all_plots = list(left_plotlist)
        if right_plotlist is not None:
            all_plots += list(right_plotlist)

        # Input checks
        message = self._init_check_left(left_plotlist, kwargs)
        # Check number of right labels, colors and thickness
        message = message or self._init_check_right(right_plotlist, kwargs)
        # Check legend
        message = message or self._init_check_legends_plots(all_plots, kwargs)
        # Backend
        if backend not in ['qwt']:
            message = 'Backend must be \'qwt\''
        if message is not None:
            raise ValueError(message)

        # Initiate the backend
        if backend == 'qwt':
            from PyExpLabSys.common.plotters_backend_qwt import QwtPlot
            self._plot = QwtPlot(parent, left_plotlist, right_plotlist,
                                 left_log, right_log, **kwargs)

        # Initiate the data
        self._data = {}
        for plot in all_plots:
            self._data[plot] = []

        self.auto_update = auto_update