예제 #1
0
def updatePlotDocstring(target):
    """
    Changes the docstring of plot function to include all
    plot options.

    Parameters
    ----------
    target: class or function
    keyprhase: string searched for in docstring
    """
    # Place import here to avoid circular dependencies
    plot_options = str(po.PlotOptions())

    def updateFunctionDocstring(func):
        docstring = func.__doc__
        if not po.EXPAND_KEYPHRASE in docstring:
            msg = "Keyword not found in method: %s"  \
                  % func.__name__
            raise RuntimeError(msg)
        new_docstring =  \
              docstring.replace(
                    po.EXPAND_KEYPHRASE, plot_options)
        func.__doc__ = new_docstring

    #
    if "__call__" in dir(target):
        # Handle a function
        updateFunctionDocstring(target)
    else:
        # Update a class
        cls = target
        for name in dir(cls):
            if name[0:4] == po.PLOT:
                method = eval("cls.%s" % name)
                updateFunctionDocstring(method)
예제 #2
0
 def testSetAxes(self):
     if IGNORE_TEST:
         return
     options = po.PlotOptions()
     options.numCol = 4
     options.numRow = 4
     _, axes, _ = self.layout._setAxes()
     if IS_PLOT:
         plt.show()
예제 #3
0
 def testSetAxes(self):
     if IGNORE_TEST:
         return
     options = po.PlotOptions()
     options.numCol = 4
     options.numRow = 4
     _, axes, _ = self.layout._setAxes()
     self.assertEqual(len(self.layout.axisPositions), DEFAULT_NUM_PLOT)
     if IS_PLOT:
         plt.show()
예제 #4
0
 def testSetAxes(self):
     if IGNORE_TEST:
         return
     options = po.PlotOptions()
     options.numCol = 4
     options.numRow = 4
     _, axes, _ = self.layout._setAxes()
     corners = [a.get_position().corners() for a in axes]
     self.assertEqual(corners[0][0][0], corners[1][0][0])
     if IS_PLOT:
         plt.show()
예제 #5
0
    def _mkPlotOptionsMatrix(timeseries1, maxCol=None, **kwargs):
        """
        Creates PlotOptions for a dense matrix of plots.

        Parameters
        ----------
        timeseries1: NamedTimeseries
        isLowerTriangular: bool
            is a lower triangular matix
        maxCol: int
            maximum number of columns
        kwargs: dict

        Returns
        -------
        PlotOptions
            assigns values to options.numRow, options.numCol
        """
        options = po.PlotOptions()
        # bins
        if po.BINS in kwargs.keys():
            bins = kwargs[po.BINS]
        else:
            bins = None
        options.bins = bins
        # Second timeseries
        if po.TIMESERIES2 in kwargs.keys():
            options.timeseries2 = kwargs[po.TIMESERIES2]
        if maxCol is None:
            if po.COLUMNS in kwargs:
                maxCol = len(kwargs[po.COLUMNS])
            else:
                maxCol = len(timeseries1.colnames)
        # States
        hasRow, hasCol = TimeseriesPlotter._getOptionValueState(
            kwargs, options)
        # Assignments based on state
        if hasRow and hasCol:
            # Have been assigned
            pass
        elif hasRow and (not hasCol):
            options.numCol = int(maxCol / options.numRow)
        elif (not hasRow) and hasCol:
            options.numRow = int(maxCol / options.numCol)
        else:
            options.numRow = 1
            options.numCol = maxCol
        if maxCol > options.numRow * options.numCol:
            options.numRow += 1
        options.initialize(timeseries1, **kwargs)
        #
        return options
예제 #6
0
    def _mkPlotOptionsLowerTriangular(timeseries1, numPlot, **kwargs):
        """
        Creates PlotOptions for a lower triangular matrix of plots.
        2*len(pairs) - N = N**2

        Parameters
        ----------
        timeseries1: NamedTimeseries
        numPlot: int
        kwargs: dict

        Returns
        -------
        PlotOptions
            assigns values to options.numRow, options.numCol
        """
        options = po.PlotOptions()
        if numPlot == 1:
            options.numRow = 1
            options.numCol = 1
        options.initialize(timeseries1, **kwargs)
        #
        return options
예제 #7
0
 def setUp(self):
     options = po.PlotOptions()
     options.numRow = 2 * DEFAULT_NUM_ROW
     options.numCol = 3 * DEFAULT_NUM_COL
     self.layout = lm.LayoutManagerMatrix(options, DEFAULT_NUM_PLOT)
예제 #8
0
 def testConstructor(self):
     options = po.PlotOptions()
     options.numRow = 2 * DEFAULT_NUM_ROW
     options.numCol = 3 * DEFAULT_NUM_COL
     with self.assertRaises(RuntimeError):
         _ = lm.LayoutManager(options, DEFAULT_NUM_PLOT)