plotnine.ggplot

class plotnine.ggplot(mapping=None, data=None, environment=None)[source]

Create a new ggplot object

Parameters
aestheticsaes

Default aesthetics for the plot. These will be used by all layers unless specifically overridden.

datadataframe

Default data for for plot. Every layer that does not have data of its own will use this one.

environmentdict, EvalEnvironment

If a variable defined in the aesthetic mapping is not found in the data, ggplot will look for it in this namespace. It defaults to using the environment/namespace. in which ggplot() is called.

draw(self, return_ggplot=False)[source]

Render the complete plot

Parameters
return_ggplotbool

If True, return ggplot object.

Returns
figFigure

Matplotlib figure

plotggplot (optional)

The ggplot object used for drawn, if return_ggplot is True.

Notes

This method does not modify the original ggplot object. You can get the modified ggplot object with return_ggplot=True.

save(self, filename=None, format=None, path=None, width=None, height=None, units='in', dpi=None, limitsize=True, verbose=True, **kwargs)[source]

Save a ggplot object as an image file

Parameters
filenamestr, optional

File name to write the plot to. If not specified, a name like “plotnine-save-<hash>.<format>” is used.

formatstr

Image format to use, automatically extract from file name extension.

pathstr

Path to save plot to (if you just want to set path and not filename).

widthnumber, optional

Width (defaults to value set by the theme). If specified the height must also be given.

heightnumber, optional

Height (defaults to value set by the theme). If specified the width must also be given.

unitsstr

Units for width and height when either one is explicitly specified (in, cm, or mm).

dpifloat

DPI to use for raster graphics. If None, defaults to using the dpi of theme, if none is set then a dpi of 100.

limitsizebool

If True (the default), ggsave will not save images larger than 50x50 inches, to prevent the common error of specifying dimensions in pixels.

verbosebool

If True, print the saving information.

kwargsdict

Additional arguments to pass to matplotlib savefig().