has2k1 / plotnine

A Grammar of Graphics for Python
https://plotnine.org
MIT License
3.92k stars 210 forks source link

Get access to artist or axes to enable rasterisation #712

Closed TyberiusPrime closed 11 months ago

TyberiusPrime commented 11 months ago

I need to dump a few thousand data points in an svg (or pdf), and would presumably be benefiting from https://matplotlib.org/stable/gallery/misc/rasterization_demo.html for my use case.

I can tell from the code that plotnine is passing (in geom_point for example) rasterized=params['raster'] to the ax object.

Is that the same thing? And how do I set that params-parameter. It's currently not in the docs and there's no test case with rasterized in it either.

Thank you!

TyberiusPrime commented 11 months ago

I found a workaround by subclassing my target geom, and yes it does indeed raster the output correctly.

class geom_point_rastered(p9.geom_point):
    def draw_panel(self, data, panel_params, coord, ax, **params):
        params['raster'] = True
        super().draw_panel(data, panel_params, coord, ax, **params)

That shouldn't be the final API though ;).

has2k1 commented 11 months ago

The raster parameter is documented. It is part of the layer, the default value is False but all geoms can set it e.g. raster=True

TyberiusPrime commented 11 months ago

My apologies, I must have been looking at an alternative history version of plotnine or something.

Could've sworn the search on the docs only lead me to the source code yesterday.

But test case has been there for years, and the docs and the change log do list it.