简体   繁体   中英

Highlight a single point on a scatter plot

I have created a scatterplot in plotly, with different color based on category. But I also want to highlight one single point (identified by a specific id) so that it stands out. So I still want my blue and yellow points, but also this specific point different from the others.

Any tips? 在此处输入图片说明

  • you have not indicated how you have built your figure. Using Plotly Express it's simple to build a figure equivalent to one presented in question
  • have used technique of adding individual point as an additional trace. For sake of demonstration it is randomly selected, but could use .loc[] to select a specific point
import numpy as np
import pandas as pd
import plotly.express as px

df = pd.DataFrame(
    {
        "x": np.random.uniform(1, 5, 200),
        "y": np.random.uniform(2, 4, 200),
        "cat": np.random.choice(["one", "two"], 200),
    }
)
fig = px.scatter(df, x="x", y="y", color="cat")

fig.add_traces(
    px.scatter(df.sample(1), x="x", y="y").update_traces(marker_size=20, marker_color="yellow").data
)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM