Пример #1
0
    def testDataRangeRight(self):
        """right axis range"""

        plot = Plot(backend='none')
        xData = numpy.arange(10) - 4.9  # range : -4.9 , 4.1
        yData = numpy.arange(10) - 6.9  # range : -6.9 , 2.1
        plot.addCurve(x=xData,
                      y=yData,
                      legend='plot_0',
                      yaxis='right')

        for logX, logY in ((False, False),
                           (True, False),
                           (True, True),
                           (False, True),
                           (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRange, yRange = self._getRanges([xData, yData],
                                                 [logX, logY])
                self.assertSequenceEqual(dataRange.x, xRange)
                self.assertIsNone(dataRange.y)
                self.assertSequenceEqual(dataRange.yright, yRange)
Пример #2
0
    def testDataRangeLeftRight(self):
        """right+left axis range"""

        plot = Plot(backend='none')

        xData_l = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        yData_l = numpy.arange(10) - 1.9  # range : -1.9 , 7.1
        plot.addCurve(x=xData_l, y=yData_l, legend='plot_l', yaxis='left')

        xData_r = numpy.arange(10) - 4.9  # range : -4.9 , 4.1
        yData_r = numpy.arange(10) - 6.9  # range : -6.9 , 2.1
        plot.addCurve(x=xData_r, y=yData_r, legend='plot_r', yaxis='right')

        for logX, logY in ((False, False), (True, False), (True, True),
                           (False, True), (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRangeL, yRangeL = self._getRanges([xData_l, yData_l],
                                                   [logX, logY])
                xRangeR, yRangeR = self._getRanges([xData_r, yData_r],
                                                   [logX, logY])
                xRangeLR = self._getRangesMinmax([xRangeL, xRangeR])
                self.assertSequenceEqual(dataRange.x, xRangeLR)
                self.assertSequenceEqual(dataRange.y, yRangeL)
                self.assertSequenceEqual(dataRange.yright, yRangeR)
Пример #3
0
    def testAddNoRemove(self):
        """add objects to the Plot"""

        plot = Plot(backend='none')
        plot.addCurve(x=(1, 2, 3), y=(3, 2, 1))
        plot.addImage(numpy.arange(100.).reshape(10, -1))
        plot.addItem(
            numpy.array((1., 10.)), numpy.array((10., 10.)), shape="rectangle")
        plot.addXMarker(10.)
Пример #4
0
    def testDataRangeCurveImage(self):
        """right+left+image axis range"""

        # overlapping ranges :
        # image sets x min and y max
        # plot_left sets y min
        # plot_right sets x max (and yright)
        plot = Plot(backend='none')

        origin = (-10, 5)
        scale = (3., 8.)
        image = numpy.arange(100.).reshape(20, 5)

        plot.addImage(image,
                      origin=origin, scale=scale, legend='image')

        xData_l = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        yData_l = numpy.arange(10) - 1.9  # range : -1.9 , 7.1
        plot.addCurve(x=xData_l,
                      y=yData_l,
                      legend='plot_l',
                      yaxis='left')

        xData_r = numpy.arange(10) + 4.1  # range : 4.1 , 13.1
        yData_r = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        plot.addCurve(x=xData_r,
                      y=yData_r,
                      legend='plot_r',
                      yaxis='right')

        imgXRange = numpy.array([0., image.shape[1] * scale[0]]) + origin[0]
        imgYRange = numpy.array([0., image.shape[0] * scale[1]]) + origin[1]

        for logX, logY in ((False, False),
                           (True, False),
                           (True, True),
                           (False, True),
                           (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRangeL, yRangeL = self._getRanges([xData_l, yData_l],
                                                   [logX, logY])
                xRangeR, yRangeR = self._getRanges([xData_r, yData_r],
                                                   [logX, logY])
                if logX or logY:
                    xRangeLR = self._getRangesMinmax([xRangeL, xRangeR])
                else:
                    xRangeLR = self._getRangesMinmax([xRangeL,
                                                      xRangeR,
                                                      imgXRange])
                    yRangeL = self._getRangesMinmax([yRangeL, imgYRange])
                self.assertSequenceEqual(dataRange.x, xRangeLR)
                self.assertSequenceEqual(dataRange.y, yRangeL)
                self.assertSequenceEqual(dataRange.yright, yRangeR)
Пример #5
0
    def testAddNoRemove(self):
        """add objects to the Plot"""

        plot = Plot(backend='none')
        plot.addCurve(x=(1, 2, 3), y=(3, 2, 1))
        plot.addImage(numpy.arange(100.).reshape(10, -1))
        plot.addItem(numpy.array((1., 10.)),
                     numpy.array((10., 10.)),
                     shape="rectangle")
        plot.addXMarker(10.)
Пример #6
0
    def testDataRangeRight(self):
        """right axis range"""

        plot = Plot(backend='none')
        plot.addCurve(x=numpy.arange(10) - 5., y=numpy.arange(10) - 7.,
                      legend='plot_0', yaxis='right')

        dataRange = plot.getDataRange()
        self.assertEqual(dataRange.x, (-5., 4.))
        self.assertIsNone(dataRange.y)
        self.assertEqual(dataRange.yright, (-7., 2.))
Пример #7
0
 def testDataRangeHiddenCurve(self):
     """curves with a hidden curve"""
     plot = Plot(backend='none')
     plot.addCurve((0, 1), (0, 1), legend='shown')
     plot.addCurve((0, 1, 2), (5, 5, 5), legend='hidden')
     range1 = plot.getDataRange()
     self.assertEqual(range1.x, (0, 2))
     self.assertEqual(range1.y, (0, 5))
     plot.hideCurve('hidden')
     range2 = plot.getDataRange()
     self.assertEqual(range2.x, (0, 1))
     self.assertEqual(range2.y, (0, 1))
Пример #8
0
 def testDataRangeHiddenCurve(self):
     """curves with a hidden curve"""
     plot = Plot(backend='none')
     plot.addCurve((0, 1), (0, 1), legend='shown')
     plot.addCurve((0, 1, 2), (5, 5, 5), legend='hidden')
     range1 = plot.getDataRange()
     self.assertEqual(range1.x, (0, 2))
     self.assertEqual(range1.y, (0, 5))
     plot.hideCurve('hidden')
     range2 = plot.getDataRange()
     self.assertEqual(range2.x, (0, 1))
     self.assertEqual(range2.y, (0, 1))
Пример #9
0
    def testDataRangeLeftRight(self):
        """right+left axis range"""

        plot = Plot(backend='none')
        plot.addCurve(x=numpy.arange(10) - 1., y=numpy.arange(10) - 2.,
                      legend='plot_left', yaxis='left')
        plot.addCurve(x=numpy.arange(10) - 5., y=numpy.arange(10) - 7.,
                      legend='plot_right', yaxis='right')

        dataRange = plot.getDataRange()
        self.assertEqual(dataRange.x, (-5., 8.))
        self.assertEqual(dataRange.y, (-2, 7.))
        self.assertEqual(dataRange.yright, (-7., 2.))
Пример #10
0
    def testDataRangeCurveImage(self):
        """right+left+image axis range"""

        # overlapping ranges :
        # image sets x min and y max
        # plot_left sets y min
        # plot_right sets x max (and yright)
        plot = Plot(backend='none')

        origin = (-10, 5)
        scale = (3., 8.)
        image = numpy.arange(100.).reshape(20, 5)

        plot.addImage(image, origin=origin, scale=scale, legend='image')

        xData_l = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        yData_l = numpy.arange(10) - 1.9  # range : -1.9 , 7.1
        plot.addCurve(x=xData_l, y=yData_l, legend='plot_l', yaxis='left')

        xData_r = numpy.arange(10) + 4.1  # range : 4.1 , 13.1
        yData_r = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        plot.addCurve(x=xData_r, y=yData_r, legend='plot_r', yaxis='right')

        imgXRange = numpy.array([0., image.shape[1] * scale[0]]) + origin[0]
        imgYRange = numpy.array([0., image.shape[0] * scale[1]]) + origin[1]

        for logX, logY in ((False, False), (True, False), (True, True),
                           (False, True), (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRangeL, yRangeL = self._getRanges([xData_l, yData_l],
                                                   [logX, logY])
                xRangeR, yRangeR = self._getRanges([xData_r, yData_r],
                                                   [logX, logY])
                if logX or logY:
                    xRangeLR = self._getRangesMinmax([xRangeL, xRangeR])
                else:
                    xRangeLR = self._getRangesMinmax(
                        [xRangeL, xRangeR, imgXRange])
                    yRangeL = self._getRangesMinmax([yRangeL, imgYRange])
                self.assertSequenceEqual(dataRange.x, xRangeLR)
                self.assertSequenceEqual(dataRange.y, yRangeL)
                self.assertSequenceEqual(dataRange.yright, yRangeR)
Пример #11
0
    def testDataRangeRight(self):
        """right axis range"""

        plot = Plot(backend='none')
        xData = numpy.arange(10) - 4.9  # range : -4.9 , 4.1
        yData = numpy.arange(10) - 6.9  # range : -6.9 , 2.1
        plot.addCurve(x=xData, y=yData, legend='plot_0', yaxis='right')

        for logX, logY in ((False, False), (True, False), (True, True),
                           (False, True), (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRange, yRange = self._getRanges([xData, yData], [logX, logY])
                self.assertSequenceEqual(dataRange.x, xRange)
                self.assertIsNone(dataRange.y)
                self.assertSequenceEqual(dataRange.yright, yRange)
Пример #12
0
    def testDataRangeCurveImage(self):
        """right+left+image axis range"""

        # overlapping ranges :
        # image sets x min and y max
        # plot_left sets y min
        # plot_right sets x max (and yright)
        plot = Plot(backend='none')
        plot.addImage(numpy.arange(100.).reshape(20, 5),
                      origin=(-10, 5), scale=(3., 8.), legend='image')
        plot.addCurve(x=numpy.arange(10) - 1., y=numpy.arange(10) - 2.,
                      legend='plot_left', yaxis='left')
        plot.addCurve(x=numpy.arange(10) + 5., y=numpy.arange(10) - 1.,
                      legend='plot_right', yaxis='right')

        dataRange = plot.getDataRange()
        self.assertEqual(dataRange.x, (-10., 14.))
        self.assertEqual(dataRange.y, (-2, 165.))
        self.assertEqual(dataRange.yright, (-1., 8.))
Пример #13
0
    def testGetCurve(self):
        """Plot.getCurve and Plot.getActiveCurve tests"""

        plot = Plot(backend='none')

        # No curve
        curve = plot.getCurve()
        self.assertIsNone(curve)  # No curve

        plot.setActiveCurveHandling(True)
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 0')
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 1')
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 2')
        plot.setActiveCurve('curve 0')

        # Active curve
        active = plot.getActiveCurve()
        self.assertEqual(active.getLegend(), 'curve 0')
        curve = plot.getCurve()
        self.assertEqual(curve.getLegend(), 'curve 0')

        # No active curve and curves
        plot.setActiveCurveHandling(False)
        active = plot.getActiveCurve()
        self.assertIsNone(active)  # No active curve
        curve = plot.getCurve()
        self.assertEqual(curve.getLegend(), 'curve 2')  # Last added curve

        # Last curve hidden
        plot.hideCurve('curve 2', True)
        curve = plot.getCurve()
        self.assertEqual(curve.getLegend(), 'curve 1')  # Last added curve

        # All curves hidden
        plot.hideCurve('curve 1', True)
        plot.hideCurve('curve 0', True)
        curve = plot.getCurve()
        self.assertIsNone(curve)
Пример #14
0
    def testGetCurve(self):
        """Plot.getCurve and Plot.getActiveCurve tests"""

        plot = Plot(backend='none')

        # No curve
        curve = plot.getCurve()
        self.assertIsNone(curve)  # No curve

        plot.setActiveCurveHandling(True)
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 0')
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 1')
        plot.addCurve(x=(0, 1), y=(0, 1), legend='curve 2')

        # Active curve
        active = plot.getActiveCurve()
        self.assertEqual(active[2], 'curve 0')  # Test curve legend
        curve = plot.getCurve()
        self.assertEqual(curve[2], 'curve 0')  # Test curve legend

        # No active curve and curves
        plot.setActiveCurveHandling(False)
        active = plot.getActiveCurve()
        self.assertIsNone(active)  # No active curve
        curve = plot.getCurve()
        self.assertEqual(curve[2], 'curve 2')  # Last added curve

        # Last curve hidden
        plot.hideCurve('curve 2', True)
        curve = plot.getCurve()
        self.assertEqual(curve[2], 'curve 1')  # Last added curve

        # All curves hidden
        plot.hideCurve('curve 1', True)
        plot.hideCurve('curve 0', True)
        curve = plot.getCurve()
        self.assertIsNone(curve)
Пример #15
0
    def testDataRangeLeftRight(self):
        """right+left axis range"""

        plot = Plot(backend='none')

        xData_l = numpy.arange(10) - 0.9  # range : -0.9 , 8.1
        yData_l = numpy.arange(10) - 1.9  # range : -1.9 , 7.1
        plot.addCurve(x=xData_l,
                      y=yData_l,
                      legend='plot_l',
                      yaxis='left')

        xData_r = numpy.arange(10) - 4.9  # range : -4.9 , 4.1
        yData_r = numpy.arange(10) - 6.9  # range : -6.9 , 2.1
        plot.addCurve(x=xData_r,
                      y=yData_r,
                      legend='plot_r',
                      yaxis='right')

        for logX, logY in ((False, False),
                           (True, False),
                           (True, True),
                           (False, True),
                           (False, False)):
            with self.subTest(logX=logX, logY=logY):
                plot.setXAxisLogarithmic(logX)
                plot.setYAxisLogarithmic(logY)
                dataRange = plot.getDataRange()
                xRangeL, yRangeL = self._getRanges([xData_l, yData_l],
                                                   [logX, logY])
                xRangeR, yRangeR = self._getRanges([xData_r, yData_r],
                                                   [logX, logY])
                xRangeLR = self._getRangesMinmax([xRangeL, xRangeR])
                self.assertSequenceEqual(dataRange.x, xRangeLR)
                self.assertSequenceEqual(dataRange.y, yRangeL)
                self.assertSequenceEqual(dataRange.yright, yRangeR)