plotnine.ggplot¶
- class plotnine.ggplot(data: DataLike | None = None, mapping: aes | None = None, environment: EvalEnvironment | None = None)[source]¶
Create a new ggplot object
- Parameters
- data
dataframe
Default data for plot. Every layer that does not have data of its own will use this one.
- mapping
aes
Default aesthetics mapping for the plot. These will be used by all layers unless specifically overridden.
- environment
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.
- data
- draw(show: bool = False) Figure [source]¶
Render the complete plot
- Parameters
- showbool (default:
python:False
) Whether to show the plot.
- showbool (default:
- Returns
- fig
Figure
Matplotlib figure
- fig
- save_helper(filename: Optional[Union[str, Path]] = None, format: Optional[str] = None, path: Optional[str] = None, width: Optional[float] = None, height: Optional[float] = None, units: str = 'in', dpi: Optional[float] = 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: Optional[Union[str, Path]] = 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
- filename
python:str
|pathlib.Path
, optional File name to write the plot to. If not specified, a name like “plotnine-save-<hash>.<format>” is used.
- format
python:str
Image format to use, automatically extract from file name extension.
- path
python: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
python:str
Units for width and height when either one is explicitly specified (in, cm, or mm).
- dpi
python: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.
- 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.- kwargs
python:dict
Additional arguments to pass to matplotlib savefig().
- filename