def data_to_imagesurface (data, **kwargs):
    """Turn arbitrary data values into a Cairo ImageSurface.

    The method and arguments are the same as data_to_argb32, except that the
    data array will be treated as 2D, and higher dimensionalities are not
    allowed. The return value is a Cairo ImageSurface object.

    Combined with the write_to_png() method on ImageSurfaces, this is an easy
    way to quickly visualize 2D data.

    """
    import cairo

    data = np.atleast_2d (data)
    if data.ndim != 2:
        raise ValueError ('input array may not have more than 2 dimensions')

    argb32 = data_to_argb32 (data, **kwargs)

    format = cairo.FORMAT_ARGB32
    height, width = argb32.shape
    stride = cairo.ImageSurface.format_stride_for_width (format, width)

    if argb32.strides[0] != stride:
        raise ValueError ('stride of data array not compatible with ARGB32')

    return cairo.ImageSurface.create_for_data (argb32, format,
                                               width, height, stride)
def data_to_imagesurface ( data , ** kwargs ) : import cairo data = np . atleast_2d ( data ) if data . ndim != 2 : raise ValueError ( 'input array may not have more than 2 dimensions' ) argb32 = data_to_argb32 ( data , ** kwargs ) format = cairo . FORMAT_ARGB32 height , width = argb32 . shape stride = cairo . ImageSurface . format_stride_for_width ( format , width ) if argb32 . strides [ 0 ] != stride : raise ValueError ( 'stride of data array not compatible with ARGB32' ) return cairo . ImageSurface . create_for_data ( argb32 , format , width , height , stride )
Turn arbitrary data values into a Cairo ImageSurface.

    The method and arguments are the same as data_to_argb32, except that the
    data array will be treated as 2D, and higher dimensionalities are not
    allowed. The return value is a Cairo ImageSurface object.

    Combined with the write_to_png() method on ImageSurfaces, this is an easy
    way to quickly visualize 2D data.