lets-plot icon indicating copy to clipboard operation
lets-plot copied to clipboard

transparent background option for ggsave and `to_*()` methods

Open Zaf4 opened this issue 1 year ago • 7 comments

From what I understand of the #121 transparent rendering was the default. But currently, when I needed to save a plot with a transparent background I could not find the option the save with the transparent background. I was expecting something like transparent = True or bg = "transparent".

I did some workaround with...


+ theme(
    panel_background=element_blank(),
    plot_background=element_blank(),
    legend_background=element_blank(),
)

but this feels very tedious and even so I could not remove legend elements' background as the following.

image

Zaf4 avatar Aug 25 '24 01:08 Zaf4

Agreed, the legend icons' background should be transparent. However, saving a plot image with transparency doesn't seem to be a common case. So there is no dedicated boolean argument for that. I'm wondering, why do you need the transparency?

alshan avatar Aug 27 '24 20:08 alshan

Agreed, the legend icons' background should be transparent.

Definitely, thanks!

I'm wondering, why do you need the transparency?

Well for one, on backgrounds with any other color than white (e.g., presentation). Sometimes people have to do use black, gray background or some specific background color on their instutions or companies. Or when you overlay/overlap multiple elements on top of each other, with non-transparent background you have to deal with the arrangments (back, front) etc., even so you might not get the look or arrangement you want, as white background covers the image or element behind.

Zaf4 avatar Aug 27 '24 22:08 Zaf4

I've removed the background from legend icons (commit).

For now, if you only need to match the background color with the background color on the slides, you can do:

bg = element_rect(fill="#d0d0d0")
... theme(
      plot_background=bg, 
      legend_background=bg)

BTW, in either case, configuring plot_background is unnecessary:

+ theme(
    panel_background=element_blank(),
    legend_background=element_blank(),
)

will lead to the same result with the default (and most other) themes and to a better result when using theme_grey().

alshan avatar Aug 29 '24 01:08 alshan

Sorry for confusion,

BTW, in either case, configuring plot_background is unnecessary:

I meant panel_background :)

alshan avatar Aug 29 '24 15:08 alshan

Thanks for the tip.

Zaf4 avatar Aug 29 '24 18:08 Zaf4

I would still really like to see the ability to save with fully transparent backgrounds.

My company for example uses slides with a dark gradient background. Creating charts in white with transparent background looks really good and it is part of our corporate design.

It is an edge case but nice nonetheless.

concimuscb avatar Oct 18 '24 07:10 concimuscb

Hi @concimuscb

+ theme(
    plot_background=element_blank(),
    legend_background=element_blank(),
)

will produce transparent plot in the coming soon release 4.5. If urgent however, you can already use today's RC version : https://pypi.org/project/lets-plot/4.5.0rc2/

alshan avatar Oct 18 '24 14:10 alshan

Amazing! Many thanks for the work and the great library :)

concimuscb avatar Oct 21 '24 09:10 concimuscb

Released : v4.5.0

alshan avatar Oct 23 '24 20:10 alshan