Skip to content

scale_color/fill_brewer() --- allow user to pass palette without specifying type #1048

@markjrieke-fortisgames

Description

@markjrieke-fortisgames

Hi! Great package! A very minor issue I ran into today is related to the scale_color_brewer() and scale_fill_brewer() functions. Depending on what type of palette you try to pass in, the method may fail.

For example, this fails because 'Set2' is part of the qualitative set.

import polars as pl
import plotnine as gg # 0.15.3

(
    pl.DataFrame({
        'group': ['A', 'A', 'A', 'B', 'B', 'B'],
        'x': [1, 2, 3, 1, 2, 3],
        'y': [1, 2, 3, 4, 5, 6]
    })
    >>
    gg.ggplot(gg.aes(
        x='x',
        y='y',
        color='group'
    )) +
    gg.geom_point() +
    gg.scale_color_brewer(palette='Set2')
).show()
AttributeError: module 'mizani._colors._palettes.brewer.sequential' has no attribute 'Set2'

This, however, displays the plot as expected

(
    pl.DataFrame({
        'group': ['A', 'A', 'A', 'B', 'B', 'B'],
        'x': [1, 2, 3, 1, 2, 3],
        'y': [1, 2, 3, 4, 5, 6]
    })
    >>
    gg.ggplot(gg.aes(
        x='x',
        y='y',
        color='group'
    )) +
    gg.geom_point() +
    gg.scale_color_brewer(type='qualitative', palette='Set2')
).show()

This might be a better issue for the mizani package, but either way, I think it'd be more natural to allow the user to pass in the palette argument without the type.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions