简体   繁体   English

突出显示散点图上的单个点

[英]Highlight a single point on a scatter plot

I have created a scatterplot in plotly, with different color based on category.我在 plotly 中创建了一个散点图,根据类别使用不同的颜色。 But I also want to highlight one single point (identified by a specific id) so that it stands out.但我也想突出一个点(由特定 id 标识),使其脱颖而出。 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使用Plotly Express可以很容易地构建一个与所提出的图形等效的图形
  • 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为了演示,它是随机选择的,但可以使用.loc[]来选择特定点
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
)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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