gpt4 book ai didi

python - Plotly:悬停信息中不可读的文本

转载 作者:行者123 更新时间:2023-12-05 02:47:17 25 4
gpt4 key购买 nike

有了 Plotly,我可以用这段代码生成条形图:

import plotly.graph_objects as go

trace0 = dict(
x=list(range(24)),
y=[163, 154, 114, 61, 32, 19, 20, 20, 26, 38, 67, 102, 132, 159],
name="Two",
type="bar",
marker={"color": "rgba(81, 133, 198, 0.3)", "line": {"width": 0}},
)
trace1 = dict(
x=list(range(24)),
y=[0, 0, 0, 4, 19, 37, 49, 49, 39, 25, 7, 1, 0, 0],
name="One",
type="bar",
marker={"color": "rgba(240, 240, 240, 1.0)", "line": {"width": 0}},
)
data = [trace0, trace1]
layout = go.Layout(
paper_bgcolor="rgba(0,0,0,0)",
plot_bgcolor="rgba(0,0,0,0)",
hovermode="x",
)
go.Figure(data=data, layout=layout).update_layout(barmode="stack")

唯一的问题是悬停信息中的标签文本不可读,因为使用的背景颜色与标签颜色太接近:

enter image description here

我该如何解决?是否可以更改悬停信息标签文本背景的颜色或悬停信息标签文本的颜色?

最佳答案

关于 plotly community forum你可以看到:

The text associated to each hoverbox is in fact the trace name. Bydefault, the line_color/marker_color is inherited by the trace namecolor to help users identify each scatter trace by color. You canchange only bgcolor and font_color

所以不,似乎没有一种方法可以在不改变痕迹的颜色属性的情况下改变你想要的东西。如果您真的想要保留颜色并克服悬停框中信息的可见性差,您可以将 hovermode="x" 更改为 hovermode="x 统一” 并改为获取此内容:

enter image description here

关于python - Plotly:悬停信息中不可读的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65061040/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com