如何在plotly中添加标签?

2024-09-27 21:32:13 发布

您现在位置:Python中文网/ 问答频道 /正文

x2016 = data[data.year == 2016].iloc[:20,:]
num_students_size  = [float(each.replace(',', '.')) for each in x2016.num_students]
international_color = [float(each) for each in x2016.international]
trace1 = go.Scatter(
x = x2016.world_rank,
y = x2016.teaching,
mode = "markers",
marker=dict(
color = international_color,
size = num_students_size,
showscale = True
),
text = x2016.university_name
)
data5 = [trace1]
iplot(data5)

这将生成气泡图,而不显示标签。如何添加标签请帮助![enter image description here]1


Tags: infordatasize标签floatyearnum
1条回答
网友
1楼 · 发布于 2024-09-27 21:32:13

您的[data5]更适合作为go.Figure()对象

这里有一个很好的顺序:https://plotly.com/python/line-and-scatter/#bubble-scatter-plots

以下是地物标签的参考: https://plotly.com/python/figure-labels/

fig.update_layout(
    title="Plot Title",
    xaxis_title="x Axis Title",
    yaxis_title="y Axis Title",
    font=dict(
        family="Courier New, monospace",
        size=18,
        color="#7f7f7f"
    )
)

fig.show()

此处提供其他相关帮助和教程: https://plotly.com/python/line-and-scatter/

因此,要在这里给出一个一般性提示,应该使用以下方法:

data5 = go.Figure(data=trace1,
    title="Plot Title",
    xaxis_title="x Axis Title",
    yaxis_title="y Axis Title"
)
iplot(data5)

相关问题 更多 >

    热门问题