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')
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
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)
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)
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.)
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)
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.)
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)
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)
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')
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.))
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')