Пример #1
0
 def testAutoscaleFromItemReference(self):
     colormap = Colormap(name='gray', normalization='linear')
     data = numpy.array([50])
     image = items.ImageData()
     image.setData(numpy.array([[0, 100]]))
     value = colormap.applyToData(data, reference=image)
     self.assertEqual(len(value), 1)
     self.assertEqual(value[0, 0], 128)
Пример #2
0
    def testNaNColor(self):
        """Test Colormap.applyToData with NaN values"""
        colormap = Colormap(name='gray', normalization='linear')
        colormap.setNaNColor('red')
        self.assertEqual(colormap.getNaNColor(), qt.QColor(255, 0, 0))

        data = numpy.array([50., numpy.nan])
        image = items.ImageData()
        image.setData(numpy.array([[0, 100]]))
        value = colormap.applyToData(data, reference=image)
        self.assertEqual(len(value), 2)
        self.assertTrue(numpy.array_equal(value[0], (128, 128, 128, 255)))
        self.assertTrue(numpy.array_equal(value[1], (255, 0, 0, 255)))
Пример #3
0
    def testVisibleExtentTracking(self):
        """Test Item's visible extent tracking"""
        image = items.ImageData()
        image.setData(numpy.arange(6).reshape(2, 3))

        listener = SignalListener()
        image._sigVisibleBoundsChanged.connect(listener)
        image._setVisibleBoundsTracking(True)
        self.assertTrue(image._isVisibleBoundsTracking())

        self.plot.addItem(image)
        self.assertEqual(listener.callCount(), 1)

        self.plot.getXAxis().setLimits(0, 1)
        self.assertEqual(listener.callCount(), 2)

        self.plot.hide()
        self.qapp.processEvents()
        # No event here
        self.assertEqual(listener.callCount(), 2)

        self.plot.getXAxis().setLimits(1, 2)
        # No event since PlotWidget is hidden, delayed to PlotWidget show
        self.assertEqual(listener.callCount(), 2)

        self.plot.show()
        self.qapp.processEvents()
        # Receives delayed event now
        self.assertEqual(listener.callCount(), 3)

        image.setOrigin((-1, -1))
        self.assertEqual(listener.callCount(), 4)

        image.setVisible(False)
        image.setOrigin((0, 0))
        # No event since item is not visible
        self.assertEqual(listener.callCount(), 4)

        image.setVisible(True)
        # Receives delayed event now
        self.assertEqual(listener.callCount(), 5)
Пример #4
0
    def testGetVisibleBounds(self):
        """Test Item.getVisibleBounds"""

        # Create test items (with a bounding box of x: [1,3], y: [0,2])
        curve = items.Curve()
        curve.setData((1, 2, 3), (0, 1, 2))

        histogram = items.Histogram()
        histogram.setData((0, 1, 2), (1, 5/3, 7/3, 3))

        image = items.ImageData()
        image.setOrigin((1, 0))
        image.setData(numpy.arange(4).reshape(2, 2))

        scatter = items.Scatter()
        scatter.setData((1, 2, 3), (0, 1, 2), (1, 2, 3))

        bbox = items.BoundingRect()
        bbox.setBounds((1, 3, 0, 2))

        xaxis, yaxis = self.plot.getXAxis(), self.plot.getYAxis()
        for item in (curve, histogram, image, scatter, bbox):
            with self.subTest(item=item):
                xaxis.setLimits(0, 100)
                yaxis.setLimits(0, 100)
                self.plot.addItem(item)
                self.assertEqual(item.getVisibleBounds(), (1., 3., 0., 2.))

                xaxis.setLimits(0.5, 2.5)
                self.assertEqual(item.getVisibleBounds(), (1, 2.5, 0., 2.))

                yaxis.setLimits(0.5, 1.5)
                self.assertEqual(item.getVisibleBounds(), (1, 2.5, 0.5, 1.5))

                item.setVisible(False)
                self.assertIsNone(item.getVisibleBounds())

                self.plot.clear()