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

Custom ordinal color schemes #1218

Closed
filipkis opened this issue Jan 11, 2023 · 3 comments
Closed

Custom ordinal color schemes #1218

filipkis opened this issue Jan 11, 2023 · 3 comments

Comments

@filipkis
Copy link

Hi,

I would like to be able to somehow specify a custom color scheme so I can create my charts with our brand colors. As far as I saw from documentation and digging through the source code, there is no way to specify a custom scheme. On can use interpolate option, but that works only when there is a range, so not with ordinal scales.

My suggestion would be that you check if scheme is an array or function and then threat it as custom color scheme, otherwise it behaves as it does now.

@Fil
Copy link
Contributor

Fil commented Jan 11, 2023

related: #630

We want to find a way to register schemes; for example maybe something like

Plot.registerScheme({ "rainbow-company" : { ordinal: ["#ef3550", "#f48fb1", "#7e57c2", "#2196f3", "#26c6da", "#43a047", …] } })

would return an instance of Plot that knows about this new scheme.

For ordinal color scales you can already specify

color: { range: ["#ef3550", "#f48fb1", "#7e57c2", "#2196f3", "#26c6da", "#43a047", …] }

but it's not exactly the same as an ordinal scheme.

@mbostock
Copy link
Member

mbostock commented Jan 11, 2023

You can set the color.range option for a custom ordinal color scheme.

Screenshot 2023-01-11 at 6 55 26 AM

Plot.plot({
  color: {
    range: ["#36a2eb", "#ff6384", "#ff9f40", "#ffcd56", "#4bc0c0", "#9966ff", "#c9cbcf"],
    legend: true
  },
  marks: [
    Plot.dot(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", stroke: "species"})
  ]
})

For ordinal scales, the color.scheme option is merely shorthand for a built-in range; you can always specify the range explicitly yourself if desired.

@filipkis
Copy link
Author

Thank you!

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

3 participants