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

Create a new ggplot object

aesthetics : aes

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

data : dataframe

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

environment : dict, 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.


Render the complete plot

return_ggplot : bool

If True, return ggplot object.

fig : Figure

Matplotlib figure

plot : ggplot (optional)

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


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

save(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

filename : str, optional

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

format : str

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

path : str

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

width : number, optional

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

height : number, optional

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

units : str

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

dpi : float

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

limitsize : bool

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

verbose : bool

If True, print the saving information.

kwargs : dict

Additional arguments to pass to matplotlib savefig().