示例#1
0
 def image(self, data=None, filename=None, title=None, alpha_mask=None,
           alpha=None, background_color=None, colormap=None,
           xdata=[None, None], ydata=[None, None],
           pixel_size=None, center_on=None,
           interpolation='linear', eliminate_outliers=None,
           xformat='%.1f', yformat='%.1f', zformat='%.1f'):
     """
     Make an image `plot item` from data
     (:py:class:`guiqwt.image.ImageItem` object or 
     :py:class:`guiqwt.image.RGBImageItem` object if data has 3 dimensions)
     """
     assert isinstance(xdata, (tuple, list)) and len(xdata) == 2
     assert isinstance(ydata, (tuple, list)) and len(ydata) == 2
     param = ImageParam(title=_("Image"), icon='image.png')
     data, filename, title = self._get_image_data(data, filename, title,
                                                  to_grayscale=True)
     if data.ndim == 3:
         return self.rgbimage(data=data, filename=filename, title=title,
                              alpha_mask=alpha_mask, alpha=alpha)
     assert data.ndim == 2, "Data must have 2 dimensions"
     if pixel_size is None:
         assert center_on is None, "Ambiguous parameters: both `center_on`"\
                                   " and `xdata`/`ydata` were specified"
         xmin, xmax = xdata
         ymin, ymax = ydata
     else:
         xmin, xmax, ymin, ymax = self.compute_bounds(data, pixel_size,
                                                      center_on)
     self.__set_image_param(param, title, alpha_mask, alpha, interpolation,
                            background=background_color,
                            colormap=colormap,
                            xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax,
                            xformat=xformat, yformat=yformat,
                            zformat=zformat)
     image = ImageItem(data, param)
     image.set_filename(filename)
     if eliminate_outliers is not None:
         image.set_lut_range(lut_range_threshold(image, 256,
                                                 eliminate_outliers))
     return image