toyplot.bitmap module

Bitmap management and manipulation.

toyplot.bitmap.to_png(data, stream, bitdepth=None)[source]

Convert an in-memory bitmap to PNG format.

Parameters:
  • data (numpy.ndarray, required) – Source array containing bitmap data to be converted. Valid array shapes are \(M \times N \times 1\) (greyscale data), \(M \times N \times 2\) (greyscale plus alpha channel), \(M \times N \times 3\) (RGB data), or \(M \times N \times 4\) (RGB + alpha). Floating point values are scaled and converted to unsigned 8 bit integers.
  • stream (file-like object, required) – Target file to receive PNG data.
  • bitdepth (integer, optional) – Override the default output bit depth. Allowed color / bitdepth combinations are: greyscale (1/2/4/8/16), greyscale + alpha (8/16), RGB (8/16), and RGB + alpha (8/16).
toyplot.bitmap.to_png_data_uri(data)[source]

Convert an in-memory bitmap to PNG format, encoded as a data: URI.

Parameters:data (numpy.ndarray, required) – Source array containing bitmap data to be converted. Valid array shapes are \(M \times N \times 1\) (greyscale data), \(M \times N \times 2\) (greyscale plus alpha channel), \(M \times N \times 3\) (RGB data), or \(M \times N \times 4\) (RGB + alpha). Floating point values are scaled and converted to unsigned 8 bit integers.
Returns:uri – A data: URI containing the base64 encoded bitmap.
Return type:str