示例#1
0
文件: testPlot.py 项目: PiRK/silx
    def testDataRangeNoPlot(self):
        """empty plot data range"""

        plot = Plot(backend='none')
        dataRange = plot.getDataRange()
        self.assertIsNone(dataRange.x)
        self.assertIsNone(dataRange.y)
        self.assertIsNone(dataRange.yright)
示例#2
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.)
示例#3
0
    def testDataRangeImageNegativeScaleY(self):
        """image data range, negative scale"""

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

        plot = Plot(backend='none')
        plot.addImage(image, origin=origin, scale=scale)

        xRange = numpy.array([0., image.shape[1] * scale[0]]) + origin[0]
        yRange = numpy.array([0., image.shape[0] * scale[1]]) + origin[1]
        yRange.sort()  # negative scale!

        ranges = {
            (False, False): (xRange, yRange),
            (True, False): (None, None),
            (True, True): (None, None),
            (False, True): (None, None)
        }

        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 = ranges[logX, logY]
                self.assertTrue(numpy.array_equal(dataRange.x, xRange),
                                msg='{0} != {1}'.format(dataRange.x, xRange))
                self.assertTrue(numpy.array_equal(dataRange.y, yRange),
                                msg='{0} != {1}'.format(dataRange.y, yRange))
                self.assertIsNone(dataRange.yright)
示例#4
0
文件: testPlot.py 项目: PiRK/silx
    def testDataRangeImage(self):
        """image data range"""

        plot = Plot(backend='none')
        plot.addImage(numpy.arange(100.).reshape(20, 5),
                      origin=(-10, 25), scale=(3., 8.))

        dataRange = plot.getDataRange()
        self.assertEqual(dataRange.x, (-10., 5.))
        self.assertEqual(dataRange.y, (25., 185.))
        self.assertIsNone(dataRange.yright)
示例#5
0
文件: testPlot.py 项目: PiRK/silx
    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.))
示例#6
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))
示例#7
0
文件: testPlot.py 项目: kif/silx
    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.)
示例#8
0
文件: testPlot.py 项目: kif/silx
    def testPlotTitleLabels(self):
        """Create a Plot and set the labels"""

        plot = Plot(backend='none')

        title, xlabel, ylabel = 'the title', 'x label', 'y label'
        plot.setGraphTitle(title)
        plot.setGraphXLabel(xlabel)
        plot.setGraphYLabel(ylabel)

        self.assertEqual(plot.getGraphTitle(), title)
        self.assertEqual(plot.getGraphXLabel(), xlabel)
        self.assertEqual(plot.getGraphYLabel(), ylabel)
示例#9
0
文件: testPlot.py 项目: kif/silx
    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)
示例#10
0
文件: testPlot.py 项目: kif/silx
    def testDataRangeImageNegativeScaleY(self):
        """image data range, negative scale"""

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

        plot = Plot(backend='none')
        plot.addImage(image,
                      origin=origin, scale=scale)

        xRange = numpy.array([0., image.shape[1] * scale[0]]) + origin[0]
        yRange = numpy.array([0., image.shape[0] * scale[1]]) + origin[1]
        yRange.sort()  # negative scale!

        ranges = {(False, False): (xRange, yRange),
                  (True, False): (None, None),
                  (True, True): (None, None),
                  (False, True): (None, None)}

        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 = ranges[logX, logY]
                self.assertTrue(numpy.array_equal(dataRange.x, xRange),
                                msg='{0} != {1}'.format(dataRange.x, xRange))
                self.assertTrue(numpy.array_equal(dataRange.y, yRange),
                                msg='{0} != {1}'.format(dataRange.y, yRange))
                self.assertIsNone(dataRange.yright)
示例#11
0
文件: testPlot.py 项目: silx-kit/silx
 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))
示例#12
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)
示例#13
0
    def testGetAllImages(self):
        """Plot.getAllImages test"""

        plot = Plot(backend='none')

        # No image
        images = plot.getAllImages()
        self.assertEqual(len(images), 0)

        # 2 images
        data = numpy.arange(100).reshape(10, 10)
        plot.addImage(data, legend='1', replace=False)
        plot.addImage(data, origin=(10, 10), legend='2', replace=False)
        images = plot.getAllImages(just_legend=True)
        self.assertEqual(list(images), ['1', '2'])
        images = plot.getAllImages(just_legend=False)
        self.assertEqual(len(images), 2)
        self.assertEqual(images[0].getLegend(), '1')
        self.assertEqual(images[1].getLegend(), '2')
示例#14
0
文件: testPlot.py 项目: kif/silx
    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)
示例#15
0
    def testGetAllScatters(self):
        """Plot.getAllImages test"""

        plot = Plot(backend='none')

        scatters = plot._getItems(kind='scatter')
        self.assertEqual(len(scatters), 0)

        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0')
        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1')
        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2')

        scatters = plot._getItems(kind='scatter')
        self.assertEqual(len(scatters), 3)
        self.assertEqual(scatters[0].getLegend(), 'scatter 0')
        self.assertEqual(scatters[2].getLegend(), 'scatter 2')

        scatters = plot._getItems(kind='scatter', just_legend=True)
        self.assertEqual(len(scatters), 3)
        self.assertEqual(list(scatters),
                         ['scatter 0', 'scatter 1', 'scatter 2'])
示例#16
0
    def testDataRangeNoPlot(self):
        """empty plot data range"""

        plot = Plot(backend='none')

        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()
                self.assertIsNone(dataRange.x)
                self.assertIsNone(dataRange.y)
                self.assertIsNone(dataRange.yright)
示例#17
0
文件: testPlot.py 项目: PiRK/silx
    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.))
示例#18
0
文件: testPlot.py 项目: silx-kit/silx
    def testGetAllImages(self):
        """Plot.getAllImages test"""

        plot = Plot(backend='none')

        # No image
        images = plot.getAllImages()
        self.assertEqual(len(images), 0)

        # 2 images
        data = numpy.arange(100).reshape(10, 10)
        plot.addImage(data, legend='1', replace=False)
        plot.addImage(data, origin=(10, 10), legend='2', replace=False)
        images = plot.getAllImages(just_legend=True)
        self.assertEqual(list(images), ['1', '2'])
        images = plot.getAllImages(just_legend=False)
        self.assertEqual(len(images), 2)
        self.assertEqual(images[0][1], '1')
        self.assertEqual(images[1][1], '2')
示例#19
0
文件: testPlot.py 项目: PiRK/silx
    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.))
示例#20
0
文件: testPlot.py 项目: kif/silx
    def testDataRangeNoPlot(self):
        """empty plot data range"""

        plot = Plot(backend='none')

        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()
                self.assertIsNone(dataRange.x)
                self.assertIsNone(dataRange.y)
                self.assertIsNone(dataRange.yright)
示例#21
0
    def testPlotCurveColorFloat(self):
        x = numpy.array([0, 1, 2])
        x2 = numpy.array([0, 1, 2, 3])
        x3 = numpy.array([-1, 0, 1, 2])
        x4 = numpy.array([-0.5, 0.5, 1.5, 2.5])
        y = numpy.array([3, 2, 5])

        # testing x values for right
        xHisto, yHisto = Plot._getHistogramValue(x, y, 'right')
        numpy.testing.assert_array_equal(xHisto,
                                         numpy.array([0, 1, 1, 2, 2, 3]))
        numpy.testing.assert_array_equal(yHisto,
                                         numpy.array([3, 3, 2, 2, 5, 5]))

        xHistoFromEdges, yHistoFromEdges = Plot._getHistogramValue(
            x2, y, 'right')
        numpy.testing.assert_array_equal(xHisto, xHistoFromEdges)
        numpy.testing.assert_array_equal(yHisto, yHistoFromEdges)
        numpy.testing.assert_array_equal(yHisto, yHistoFromEdges)

        # testing y values for left
        xHisto, yHisto = Plot._getHistogramValue(x, y, 'left')
        numpy.testing.assert_array_equal(xHisto,
                                         numpy.array([-1, 0, 0, 1, 1, 2]))
        numpy.testing.assert_array_equal(yHisto,
                                         numpy.array([3, 3, 2, 2, 5, 5]))

        xHistoFromEdges, yHistoFromEdges = Plot._getHistogramValue(
            x3, y, 'left')
        numpy.testing.assert_array_equal(xHisto, xHistoFromEdges)
        numpy.testing.assert_array_equal(yHisto, yHistoFromEdges)

        # testing y values for center
        xHisto, yHisto = Plot._getHistogramValue(x, y, 'center')
        numpy.testing.assert_array_equal(
            xHisto, numpy.array([-0.5, 0.5, 0.5, 1.5, 1.5, 2.5]))
        numpy.testing.assert_array_equal(yHisto,
                                         numpy.array([3, 3, 2, 2, 5, 5]))

        xHistoFromEdges, yHistoFromEdges = Plot._getHistogramValue(
            x4, y, 'center')
        numpy.testing.assert_array_equal(xHisto, xHistoFromEdges)
示例#22
0
文件: testPlot.py 项目: kif/silx
    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)
示例#23
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)
示例#24
0
    def testPlotTitleLabels(self):
        """Create a Plot and set the labels"""

        plot = Plot(backend='none')

        title, xlabel, ylabel = 'the title', 'x label', 'y label'
        plot.setGraphTitle(title)
        plot.setGraphXLabel(xlabel)
        plot.setGraphYLabel(ylabel)

        self.assertEqual(plot.getGraphTitle(), title)
        self.assertEqual(plot.getGraphXLabel(), xlabel)
        self.assertEqual(plot.getGraphYLabel(), ylabel)
示例#25
0
    def testGetImage(self):
        """Plot.getImage and Plot.getActiveImage tests"""

        plot = Plot(backend='none')

        # No image
        image = plot.getImage()
        self.assertIsNone(image)

        plot.addImage(((0, 1), (2, 3)), legend='image 0', replace=False)
        plot.addImage(((0, 1), (2, 3)), legend='image 1', replace=False)

        # Active image
        active = plot.getActiveImage()
        self.assertEqual(active.getLegend(), 'image 0')
        image = plot.getImage()
        self.assertEqual(image.getLegend(), 'image 0')

        # No active image
        plot.addImage(((0, 1), (2, 3)), legend='image 2', replace=False)
        plot.setActiveImage(None)
        active = plot.getActiveImage()
        self.assertIsNone(active)
        image = plot.getImage()
        self.assertEqual(image.getLegend(), 'image 2')

        # Active image
        plot.setActiveImage('image 1')
        active = plot.getActiveImage()
        self.assertEqual(active.getLegend(), 'image 1')
        image = plot.getImage()
        self.assertEqual(image.getLegend(), 'image 1')
示例#26
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)
示例#27
0
文件: testPlot.py 项目: kif/silx
    def testGetImage(self):
        """Plot.getImage and Plot.getActiveImage tests"""

        plot = Plot(backend='none')

        # No image
        image = plot.getImage()
        self.assertIsNone(image)

        plot.addImage(((0, 1), (2, 3)), legend='image 0', replace=False)
        plot.addImage(((0, 1), (2, 3)), legend='image 1', replace=False)

        # Active image
        active = plot.getActiveImage()
        self.assertEqual(active[1], 'image 0')  # Test image legend
        image = plot.getImage()
        self.assertEqual(image[1], 'image 0')  # Test image legend

        # No active image
        plot.addImage(((0, 1), (2, 3)), legend='image 2', replace=False)
        plot.setActiveImage(None)
        active = plot.getActiveImage()
        self.assertIsNone(active)
        image = plot.getImage()
        self.assertEqual(image[1], 'image 2')  # Test image legend

        # Active image
        plot.setActiveImage('image 1')
        active = plot.getActiveImage()
        self.assertEqual(active[1], 'image 1')
        image = plot.getImage()
        self.assertEqual(image[1], 'image 1')  # Test image legend
示例#28
0
    def testAddGetScatter(self):

        plot = Plot(backend='none')

        # No curve
        scatter = plot._getItem(kind="scatter")
        self.assertIsNone(scatter)  # No curve

        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 0')
        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 1')
        plot.addScatter(x=(0, 1), y=(0, 1), value=(0, 1), legend='scatter 2')
        plot._setActiveItem('scatter', 'scatter 0')

        # Active curve
        active = plot._getActiveItem(kind='scatter')
        self.assertEqual(active.getLegend(), 'scatter 0')

        scatter1 = plot._getItem(kind='scatter', legend='scatter 1')
        self.assertEqual(scatter1.getLegend(), 'scatter 1')
示例#29
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)
示例#30
0
文件: testPlot.py 项目: kif/silx
    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)