Skip to content

Wrong coloring logic when switching the color_by value #191

@hadim

Description

@hadim

When switching the color_by value dynamically, it seems like the coloring logic is kept to the original column and does not consider the new data type.

Consider the code below:

import pandas as pd
import jscatter
import numpy as np


n = 50
categories = [f"cat_{i}" for i in range(3)]

df = pd.DataFrame({
    "x": np.random.rand(n),
    "y": np.random.rand(n),
    "length": np.random.rand(n),
    "cat": np.random.choice(categories, size=n),
})

df["cat"] = df["cat"].astype("category")


scatter = jscatter.Scatter(
    data=df,
    x="x",
    y="y",
    color_by="cat",
    size=10,
    legend=True,
    tooltip=True,
    tooltip_properties=["cat"],
    tooltip_size="large",
    height=200,
    width=500,
    legend_size="large",
)

scatter.show()
Image

Now switch the color_by value:

scatter.color(by="length")

And the colors are now wrong:

Image

While it should be:

Image

Note that the other way around (from continuous to category) fail as well.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions