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

ENH: support more style params for guide_colorbar #701

Closed
wants to merge 1 commit into from

Conversation

daylinmorgan
Copy link
Contributor

This PR addresses #653, along with adding the other related parameters from the ggplot2 implementation.

Example:

import numpy as np
import pandas as pd

from plotnine import (
    aes,
    element_blank,
    geom_tile,
    ggplot,
    guide_colorbar,
    scale_fill_continuous,
    theme,
)

df = pd.DataFrame(
    {
        "value": np.random.randn(100),
        "variable": np.tile(["A", "B", "C", "D", "E"], 20),
        "time": np.repeat(np.arange(1, 21), 5),
    }
)

(
    ggplot(df, aes("variable", "time", fill="value"))
    + geom_tile()
    + scale_fill_continuous(
        guide=guide_colorbar(frame_color="black", ticks_color="black")
    )
    + theme(panel_background=element_blank(),figure_size=(3,3))
)

colorbar

@has2k1
Copy link
Owner

has2k1 commented Aug 8, 2023

@daylinmorgan I will look at this before of the next release. The styling needs to be integrated with the theming system. You can take a crack at it if you wish, otherwise I will do it.

@daylinmorgan
Copy link
Contributor Author

The styling needs to be integrated with the theming system.

Could you elaborate more what you mean by this? Do these overlap with any of the current themeable elements?

@has2k1
Copy link
Owner

has2k1 commented Aug 9, 2023

Could you elaborate more what you mean by this?

The rectangle for the colorbar should be themeable with element_rect(...) and, the lines for the ticks should be themeable with element_line(...).

How it works is, we store the Matplotlib artists that should be themeable in a dictionary theme._targets. Then a class in themes/themeable.py does the actual "theming" i.e. setting the properties of the artist.

@daylinmorgan
Copy link
Contributor Author

Ah! It wasn't clear just using the docs for ggplot2 that the guide_colorbar actually supports a theme object as well.

@has2k1
Copy link
Owner

has2k1 commented Feb 7, 2024

I have merged this in 18f397e4 and completely refactored the guides to mainly be styled through the local theme parameter or the global theme. Plus there is now full control over the positioning of guides.

@has2k1 has2k1 closed this Feb 7, 2024
@daylinmorgan
Copy link
Contributor Author

Sounds great! Looking forward to the next release.

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

Successfully merging this pull request may close these issues.

2 participants