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

Plotnine legend position is reset after using patchworklib #17

Closed
iddryg opened this issue Jul 14, 2022 · 3 comments
Closed

Plotnine legend position is reset after using patchworklib #17

iddryg opened this issue Jul 14, 2022 · 3 comments

Comments

@iddryg
Copy link

iddryg commented Jul 14, 2022

I've noticed that my original ggplot legend position is not maintained after patching together. I used...

  • theme(legend_position=(.5, -0.02), legend_direction='horizontal')

...to position it underneath each individual ggplot before combining with patchworklib. However, after patching together, the legend goes back to the right side for every sub-plot.

Is this related to the same issue as in #15? Thanks.

@ponnhide
Copy link
Owner

ponnhide commented Jul 19, 2022

I'm sorry for the late response. Could you share the example code that can reproduce the issue you posted?
Now, I have tried to use theme(legend_position=(xx, xxxx), legend_direction='horizontal') as follows. (using plotnine v0.9.0 and patchworklib v0.4.3)

import patchworklib as pw
from plotnine import *
from plotnine.data import *
g1 = pw.load_ggplot(ggplot(mtcars, aes('wt', 'mpg', color='factor(gear)')) 
                    + geom_point() + stat_smooth(method='lm')
                    + facet_wrap('~gear')
                    + theme(legend_position=(.5, -0.2), legend_direction='horizontal'),
                    figsize=(3,3))
g2 = pw.load_ggplot(ggplot(data=diamonds) 
                    + geom_bar(mapping=aes(x="cut", fill="clarity"), position="dodge")
                    + theme(legend_position=(.5, -0.2), legend_direction='horizontal'),
                    figsize=(5, 2))
(g1.outline|g2.outline).savefig()

download

Actually, patchworklib cannot perfectly reproduce the original legend position in the single plotnine plot, so please adjust according to the output figure.

@iddryg
Copy link
Author

iddryg commented Jul 19, 2022

Patchworklib_test.pdf

Hmm, your example looks good. Mine didn't work... You can see the original ggplots have the legend below, but after using patchworklib they get reset to the right. Let me check my versions. Plotnine version 0.8.0, patchworklib version 0.4.2. I'll update and see if that helps.

@iddryg
Copy link
Author

iddryg commented Jul 19, 2022

Okay, I updated versions to plotnine 0.9.0 and patchworklib to 0.4.3 and it looks like yours now! Perfect, thanks.

@iddryg iddryg closed this as completed Jul 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants