plotnine.ggplot

class plotnine.ggplot(data: DataLike | None = None, mapping: aes | None = None, environment: EvalEnvironment | None = None)[source]

Create a new ggplot object

Parameters:
datadataframe

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

mappingaes

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

environmentEvalEnvironment

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(show: bool = False) Figure[source]

Render the complete plot

Parameters:
showbool (default: False)

Whether to show the plot.

Returns:
figFigure

Matplotlib figure

save_helper(filename: str | Path | None = None, format: str | None = None, path: str | None = None, width: float | None = None, height: float | None = None, units: str = 'in', dpi: float | None = None, limitsize: bool = True, verbose: bool = True, **kwargs: Any) mpl_save_view[source]

Create MPL figure that will be saved

Notes

This method has the same arguments as ggplot.save(). Use it to get access to the figure that will be saved.

save(filename: str | Path | None = None, format: str | None = None, path: str = '', width: float | None = None, height: float | None = None, units: str = 'in', dpi: float | None = None, limitsize: bool = True, verbose: bool = True, **kwargs: Any)[source]

Save a ggplot object as an image file

Parameters:
filenamestr | pathlib.Path, 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().