toyplot.png module

Functions to render PNG images.

toyplot.png.render(canvas, fobj=None, width=None, height=None, scale=None)[source]

Render the PNG bitmap representation of a canvas.

By default, canvas dimensions in CSS pixels are mapped directly to pixels in the output PNG image. Use one of width, height, or scale to override this behavior.

Parameters:
  • canvas (toyplot.canvas.Canvas) – Canvas to be rendered.

  • fobj (file-like object or string, optional) – The file to write. Use a string filepath to write data directly to disk. If None (the default), the PNG data will be returned to the caller instead.

  • width (number, optional) – Specify the width of the output image in pixels.

  • height (number, optional) – Specify the height of the output image in pixels.

  • scale (number, optional) – Ratio of output image pixels to canvas pixels.

Returns:

png – Returns None if the caller specifies the fobj parameter, returns the PNG image data otherwise.

Return type:

bytes containing PNG image data, or None

Notes

The output PNG is rendered using toyplot.reportlab.png.render(). This is subject to change.