Skip to content

colors argument to add_trace is only respected if the trace type *isn't* specified in the plot_ly call #2474

@wkumler

Description

@wkumler

I'd expect these two lines of code to produce the same output, but only the first does what I expect (uses the colors argument to pick a palette for the points):

plot_ly(data = iris) %>%
  add_trace(x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, colors = "Blues", mode = "markers")
Image
plot_ly(data = iris, type="scatter") %>%
  add_trace(x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, colors = "Blues", mode = "markers")
Image

This seems backwards since I added the type="scatter" to avoid the warning about guessing the trace type, only to have my palette disappear.

Curiously, this behavior isn't present if everything is specified in the same call:

plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, colors = "Blues")
plot_ly(data = iris, x = ~Sepal.Length, y = ~Sepal.Width, color = ~Species, colors = "Blues", type="scatter")

both return

Image

Is colors the correct way to pass a palette to a specific layer? In other places it seems like it's actually colorspace? I know scatter doesn't have a colors argument in schema() (e.g. #1699) but clearly it's working when the type is inferred and I would like to provide a palette...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions