Пример #1
0
 def setFigPlotAttribute(ax, name: str, **kwargs):
     value = self.__getattribute__(name)
     if value is not None:
         func = eval("ax.set_%s" % name)
         statement = StatementManager(func)
         statement.addPosarg(self.get(name, **kwargs))
         statement.execute()
Пример #2
0
    def do(self, ax, statement: StatementManager = None, **kwargs):
        """
        Enacts options taking into account the scope of the option.
        Note that options related to NUM_ROW, NUM_COL are handled elsewhere.

        Parameters
        ----------
        ax: Matplotlib.Axes
        statement: StatementManager
        kwargs: dict
            arguments for get
        """
        def setLineAttribute(ax,
                             name: str,
                             statement: StatementManager = None,
                             **kwargs):
            """
            Updates the statement for the line being plotted.
            """
            if statement is None:
                return
            if "Axes.plot" in str(statement.func):
                # Some options are not alloed for line plots
                if name in [MARKER, MARKERSIZE]:
                    return
            value = self.get(name, **kwargs)
            if value is not None:
                if name in AX_STATEMENT_KW.keys():
                    dct = {AX_STATEMENT_KW[name]: value}
                else:
                    dct = {name: value}
                statement.addKwargs(**dct)

        #
        def setFigPlotAttribute(ax, name: str, **kwargs):
            value = self.__getattribute__(name)
            if value is not None:
                func = eval("ax.set_%s" % name)
                statement = StatementManager(func)
                statement.addPosarg(self.get(name, **kwargs))
                statement.execute()

        # Attributes processed by this method
        names = [
            ALPHA, COLOR, LINESTYLE, MARKER, MARKERSIZE, XLABEL, YLABEL, XLIM,
            XTICKLABELS, YLIM, YTICKLABELS
        ]
        for name in names:
            kwarg = KWARG_DCT[name]
            if kwarg.scope == ExKwarg.LINE:
                setLineAttribute(ax, name, statement=statement, **kwargs)
            else:
                setFigPlotAttribute(ax, name, **kwargs)
        if statement is not None:
            statement.execute()
        # Other attributes
        if self.title is not None:
            title = self.get(TITLE, **kwargs)
            titlePosition = self.get(TITLE_POSITION, **kwargs)
            titleFontsize = self.get(TITLE_FONTSIZE, **kwargs)
            statement = StatementManager(ax.set_title)
            statement.addPosarg(title)
            if self.titlePosition is not None:
                statement.addKwargs(x=titlePosition[0])
                statement.addKwargs(y=titlePosition[1])
                statement.addKwargs(transform=ax.transAxes)
            if self.titleFontsize is not None:
                statement.addKwargs(fontsize=titleFontsize)
            statement.execute()
        value = self.__getattribute__(SUBPLOT_WIDTH_SPACE)
        if value is not None:
            plt.subplots_adjust(wspace=value)
        if self.legend is not None:
            ax.legend(self.legend)
        if self.suptitle is not None:
            plt.suptitle(self.suptitle)