在散点图中有没有可能有阴影的点? [英] Is it possible to have points which shade out in scatter plot?

查看:18
本文介绍了在散点图中有没有可能有阴影的点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以在散点图中画出心形和其他形状。但是,是否有可能使图中的点变暗[在圆圈中],如下图所示,旁边带有文本

感谢您提前回复。

推荐答案

可以。您需要将该值添加到plotly.graph_objects.Scatter.text属性。我怀疑您的text属性有一个心形符号/表情符号,因此要在文本中输入的值按您的偏好排序,以匹配这些点,并将心形符号附加到该列表中。以下是如何做到这一点的通用示例:


import dash
from dash import html, dcc
import pandas as pd
import numpy as np
import plotly.graph_objects as go

app = dash.Dash()

df = pd.DataFrame([
    np.random.randint(1, 5, 5),
    np.random.randint(1, 5, 5),
    ["text_1", "text_2", "text_3", "text_4", "text_5"]]
).transpose()

df.columns = ["x", "y", "text"]

def add_text_to_heart(st):
    return f"♥ {st}"

df["text"] = df["text"].apply(add_text_to_heart)

app.layout = html.Div([
    dcc.Graph(figure=(go.Figure(
    go.Scatter(
        x=df["x"],
        y=df["y"],
        mode="text",
        text=df["text"],
        textfont_size=20,
        textfont_color=np.random.choice(["red","yellow","blue"], 10)
    )
)))
])

if __name__ == "__main__":
    app.run_server()

这篇关于在散点图中有没有可能有阴影的点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆