Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plot SVGs are massive in size due to color legend #129

Open
dnjst opened this issue Aug 1, 2024 · 2 comments
Open

Plot SVGs are massive in size due to color legend #129

dnjst opened this issue Aug 1, 2024 · 2 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@dnjst
Copy link

dnjst commented Aug 1, 2024

Describe the bug
I would like to make publication-quality editable figures of LIANA plots in SVG format, but am coming up an obstacle where the output SVG files are massive in size (~2 MB) and thus cause memory issues and crashing when loaded into a program such as powerpoint/illustrator, and even inkscape struggles.

The reason seems to be that the color bar legend for the annotation colors (here "magnitude_rank") is made up of thousands of tiny rectangles which is blowing up the number of points in the SVG.

This may be a plotnine issue, but perhaps you could look into it and maybe suggest a workaround?

For instance, although not ideal, is it possible to optionally rasterize the colorbar and leave the rest as SVG, like how scanpy does with UMAPs of thousands of points?

I will also look in how to report/address this upstream if necessary...

To Reproduce
my_plot = li.pl.dotplot(adata = adata,
colour='magnitude_rank',
inverse_colour=True,
size='specificity_rank',
inverse_size=True,
source_labels=['CD34+', 'CD56+ NK', 'CD14+ Monocyte'],
target_labels=['CD34+', 'CD56+ NK'],
filter_fun=lambda x: x['specificity_rank'] <= 0.01,
)
my_plot.save("myfigure.svg", transparent=True)

Screenshots
If applicable, add screenshots with a traceback to any exception.

@dnjst dnjst added bug Something isn't working help wanted Extra attention is needed labels Aug 1, 2024
@dbdimitrov
Copy link
Collaborator

dbdimitrov commented Aug 5, 2024

Hi @dnjst,

Indeed, this is purely on the plotnine side, but I found a way to rasterize the colour guide:

p2 = p + p9.guides(color=p9.guide_colorbar(display='raster', nbin=50))
p2.save('test2.pdf', dpi=300)

However, for some reason in my case it would move the colour bar whenever I tried to load it into inkscape... So, if this happens to you, you would have to drag it back 😅 😅 😅 Not sure if this is a plotnine or an inkscape 'feature'.

I used plotnine == '0.13.3'. I also tried with other 0.13.x versions but it did not resolve the shifting, while older versions have a different API and did not actually rasterize it...

Genuinely future liana versions should transition to matplotlib completely.

@dnjst
Copy link
Author

dnjst commented Aug 8, 2024

Thanks for the code - yes I tried that and my experience was it saved the filesize blowing up issue, but it moved the colorbar to the bottom left corner also!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants