cowpatch.svg_utils

Module Contents

Functions

gg_to_svg(gg, width, height, dpi[, limitsize, eps, ...])

Convert plotnine ggplot figure to svg and return it (with close to perfect

mpt_to_svg(gg, width, height, dpi)

cowpatch.svg_utils.gg_to_svg(gg, width, height, dpi, limitsize=True, eps=0.01, maxIter=20, min_size_px=10)[source]

Convert plotnine ggplot figure to svg and return it (with close to perfect sizing).

Parameters
  • gg (plotnine.ggplot.ggplot) – object to save as a png image

  • width (float) – width in inches to be passed to the plotnine’s ggplot.save function

  • height (float) – height in inches to be passed to the plotnine’s ggplot.save function

  • dpi (int) – dots per inch, to be passed to the plotnine’s ggplot.save function

  • limitsize (boolean) – logic if plotnine’s ggplot.save function should check if the requested width and height in inches are greater than 50 (assumes the user accidentally entered in these values w.r.t. pixels)

  • eps (float) – maximum allowed difference between height and width output versus the desired output

  • maxIter (int) – maximum number of steps that can be used to the difference between desired and output height and width within minimum distance

  • min_size_px (int) – early stopping rule if converging height or width has a pixel size smaller than or equal to this value (assumes process will not converge)

Returns

(aka an svg representation)

Return type

svgutils.tranform representation of the ggplot object

Notes

Code idea motified by the stackoverflow question here, https://stackoverflow.com/questions/8598673/how-to-save-a-pylab-figure-into-in-memory-file-which-can-be-read-into-pil-image/8598881 and truly influenced by svgutils.transform.from_mpl function.

cowpatch.svg_utils.mpt_to_svg(gg, width, height, dpi)[source]