has2k1 / plotnine

A Grammar of Graphics for Python

Home Page:https://plotnine.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow to pass `limitsize=False` to `theme()`

krassowski opened this issue · comments

When I call

ggplot() + theme(figure_size=(16, 34))

I get an error:

PlotnineError: "Dimensions (width=16, height=34) exceed 25 inches (height and width are specified in inches/cm/mm, not pixels). If you are sure you want these dimensions, use 'limitsize=False'."

When I try to follow the instruction with:

ggplot() + theme(figure_size=(16, 34), limitsize=False)

I get:

PlotnineError: 'There no themeable element called: limitsize'

Searching the repo and looking at #783 (comment) I understand that I would need to use p.save() to pass this argument. But I do not want to save the plot to a file - I am plotting it in a Jupyter Notebook and not calling save at all.

Since theme is where we pass figure_size it would appear reasonable to me to allow to pass limitsize there. Alternatively, the figure_size argument could also accept something like:

ggplot() + theme(figure_size={"width": 16, "height": 34, "limit": False})

I think a better solution is to create global option at plotnine.options.limitsize, then use it as follows.

from plotnine.options import set_option
set_option("limitsize", False)