def plot_2D(x, y, data, title, xlabel="X [um]", ylabel="Y [um]"): xmin, xmax = x.min() * 1e6, x.max() * 1e6 ymin, ymax = y.min() * 1e6, y.max() * 1e6 origin = (xmin, ymin) scale = (abs((xmax - xmin) / len(x)), abs((ymax - ymin) / len(y))) # PyMCA inverts axis!!!! histogram must be calculated reversed data_to_plot = [] for y_index in range(0, len(y)): x_values = [] for x_index in range(0, len(x)): x_values.append(data[x_index, y_index]) x_values.reverse() data_to_plot.append(x_values) plot_canvas = ImageView() #plot_canvas = Plot2D() plot_canvas.setGraphTitle(title) plot_canvas.addImage(numpy.array(data_to_plot), xlabel=xlabel, ylabel=ylabel, legend="data", origin=origin, scale=scale, replace=True) plot_canvas.toolBar() plot_canvas.show()
def setUp(self): super(TestImageView, self).setUp() self.plot = ImageView() self.plot.show() self.qWaitForWindowExposed(self.plot)
class TestImageView(TestCaseQt): """Tests of ImageView widget.""" def setUp(self): super(TestImageView, self).setUp() self.plot = ImageView() self.plot.show() self.qWaitForWindowExposed(self.plot) def tearDown(self): self.qapp.processEvents() self.plot.setAttribute(qt.Qt.WA_DeleteOnClose) self.plot.close() del self.plot self.qapp.processEvents() super(TestImageView, self).tearDown() def testSetImage(self): """Test setImage""" image = numpy.arange(100).reshape(10, 10) self.plot.setImage(image, reset=True) self.qWait(100) self.assertEqual(self.plot.getXAxis().getLimits(), (0, 10)) self.assertEqual(self.plot.getYAxis().getLimits(), (0, 10)) # With reset=False self.plot.setImage(image[::2, ::2], reset=False) self.qWait(100) self.assertEqual(self.plot.getXAxis().getLimits(), (0, 10)) self.assertEqual(self.plot.getYAxis().getLimits(), (0, 10)) self.plot.setImage(image, origin=(10, 20), scale=(2, 4), reset=False) self.qWait(100) self.assertEqual(self.plot.getXAxis().getLimits(), (0, 10)) self.assertEqual(self.plot.getYAxis().getLimits(), (0, 10)) # With reset=True self.plot.setImage(image, origin=(1, 2), scale=(1, 0.5), reset=True) self.qWait(100) self.assertEqual(self.plot.getXAxis().getLimits(), (1, 11)) self.assertEqual(self.plot.getYAxis().getLimits(), (2, 7)) self.plot.setImage(image[::2, ::2], reset=True) self.qWait(100) self.assertEqual(self.plot.getXAxis().getLimits(), (0, 5)) self.assertEqual(self.plot.getYAxis().getLimits(), (0, 5)) def testColormap(self): """Test get|setColormap""" image = numpy.arange(100).reshape(10, 10) self.plot.setImage(image) # Colormap as dict self.plot.setColormap({'name': 'viridis', 'normalization': 'log', 'autoscale': False, 'vmin': 0, 'vmax': 1}) colormap = self.plot.getColormap() self.assertEqual(colormap.getName(), 'viridis') self.assertEqual(colormap.getNormalization(), 'log') self.assertEqual(colormap.getVMin(), 0) self.assertEqual(colormap.getVMax(), 1) # Colormap as keyword arguments self.plot.setColormap(colormap='magma', normalization='linear', autoscale=True, vmin=1, vmax=2) self.assertEqual(colormap.getName(), 'magma') self.assertEqual(colormap.getNormalization(), 'linear') self.assertEqual(colormap.getVMin(), None) self.assertEqual(colormap.getVMax(), None) # Update colormap with keyword argument self.plot.setColormap(normalization='log') self.assertEqual(colormap.getNormalization(), 'log') # Colormap as Colormap object cmap = Colormap() self.plot.setColormap(cmap) self.assertIs(self.plot.getColormap(), cmap)