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

How to turn off/modify legend in Patchworklib #13

Closed
BroDa1i opened this issue Jun 8, 2022 · 4 comments
Closed

How to turn off/modify legend in Patchworklib #13

BroDa1i opened this issue Jun 8, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@BroDa1i
Copy link

BroDa1i commented Jun 8, 2022

Hello, thank you for your amazing tool so that I can make better pictures for my graduation thesis. I'm now having trouble on turning off/modifying the size of the legend in the combined pictures. I'm not a professional programmer so I'm not sure if it's my problem or if this function is not included in this package. I'll paste my code below:

p1 = (
        ggplot(flight_01, aes(x='t_plot', y='FL1', shape="legend", color="legend"))
        + geom_point(alpha=0.5, size=0.5)
        + scale_x_datetime(labels=date_format('%H:%M'))
        + scale_color_manual(values=['tomato'], breaks=['trajectory'])
        + xlab("time [h]")
        + ylab("altitude x 10^2 [ft]")
        + ggtitle("Flight trajectory "+str(num[0])+"")
        + theme_gray()
        + theme(
                legend_title=element_blank(),
                figure_size=(12, 9),
                legend_position='none',
                legend_box='horizontal',
        )
)

p2 = (
        ggplot(flight_02, aes(x='t_plot', y='FL1', shape="legend", color="legend"))
        + geom_point(alpha=0.5, size=0.5)
        + scale_x_datetime(labels=date_format('%H:%M'))
        + scale_color_manual(values=['tomato'], breaks=['trajectory'])
        # + scale_x_datetime(breaks="30 minute", labels=date_format('%H:%M'))
        + xlab("time [h]")
        + ylab("altitude x 10^2 [ft]")
        + ggtitle("Flight trajectory "+str(num[1])+"")
        + theme_gray()
        + theme(
                legend_title=element_blank(),
                figure_size=(12, 9),
                legend_position='right',
                legend_box='horizontal',
                legend_text=element_text(size=5)
        )
)
print(p1)
print(p2)

p1 = pw.load_ggplot(p1, figsize=(4, 3))
p2 = pw.load_ggplot(p2, figsize=(4, 3))
g1234 = p1|p2
g1234.savefig("G:/DA/combi.png")

As you can see I turn the legend off for p1 and keep only p2. I also turn off the word "legend" for p2 and make the text size smaller so that the width of the combined pic can be thinner.

But in the combined pic g1234, the word "legend" is still there and the size of the legend remains the same as the title, which I didn't change at all. And the pics made by "print" are working as I wanted.

Could you give me some advice on this? Thx a lot!

@BroDa1i
Copy link
Author

BroDa1i commented Jun 8, 2022

combi

Maybe this will help you more on understanding my problem.

@ponnhide
Copy link
Owner

ponnhide commented Jun 9, 2022

Thank you for your detailed reports.
It's problem with patchworklib.
The implementation of plotnine's legend is totally different from the one of matplotlib's legend.
Therefore, the current patchworklib still cannot handle plotnine's legend properly in some cases...
Now, I'm trying to fix the problem, sorry for the inconvenience.

@ponnhide ponnhide closed this as not planned Won't fix, can't repro, duplicate, stale Jun 9, 2022
@ponnhide ponnhide reopened this Jun 9, 2022
@BroDa1i
Copy link
Author

BroDa1i commented Jun 9, 2022

Thank you for your detailed reports. It's problem with patchworklib. The implementation of plotnine's legend is totally different from the one of matplotlib's legend. Therefore, the current patchworklib still cannot handle plotnine's legend properly in some cases... Now, I'm trying to fix the problem, sorry for the inconvenience.

Thx a lot! You're so nice and I can't wait to see the next update!

@ponnhide ponnhide added the enhancement New feature or request label Jun 13, 2022
@ponnhide
Copy link
Owner

@BroDa1i I'm sorry for the late notice.
I have recently updated patchworklib. If you use patchworklib v0.4.5 and plotnine v0.9.0, the above problem will be probably solved.
If you face any problems, please let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants