汪汪一只猫
您可以轻松地在 0 和 1 之间重新缩放 pandas 系列,并将其用作参数, rgba(red,green,blue,opacity)例如图中某个标记的不透明度在 0 和 1 之间color='rgba(100,0,255,'+opac+')'。opac标记的颜色属性对于任何 都是唯一的go.Scatter(),因此您必须为每个点添加一个唯一的轨迹。然后,同时,您可以为标记的轮廓设置颜色(如果您愿意的话,还可以设置不透明度)使用marker=dict(line=dict(color='rgba(100,0,255,1)'))在下图中,我将轮廓颜色设置为“rgba(100,0,255,1)”,标记填充的不透明度根据上述逻辑变化。这样,最高值将显示为完全“填充”的标记:但是你也可以设置一个定义更明确的行,例如,line=dict(color='rgba(0,0,0,1)', width = 2)得到这样的东西:现在您可以尝试所有rgba参数来找到您喜欢的颜色。完整代码:# importsimport plotly.graph_objects as goimport pandas as pdimport numpy as np# sample data in the form of an hourltnp.random.seed(1234)tseries = pd.date_range("01.01.2020", "01.04.2020", freq="H")data = np.random.randint(-100, 100, size=(len(tseries), 3))df = pd.DataFrame(data=data)df.columns=list('ABC')df['C_scaled'] = df['C'].max()/df['C']df['C_scaled'] = (df['C']-df['C'].min())/(df['C'].max()-df['C'].min())df = df.sort_values(by=['C_scaled'], ascending=False)fig=go.Figure()for ix in df.index: d = df.iloc[ix] opac = str(d['C_scaled']) fig.add_trace(go.Scatter(x=[d['A']], y=[d['B']], showlegend=False, marker=dict(size = 14, color='rgba(100,0,255,'+opac+')', line=dict(color='rgba(0,0,0,1)', width = 2))) ) fig.show()编辑: Hoverinfo 的副作用只需包含以下内容即可编辑 hoverinfo,以便在悬停时始终显示 x 和 y 值到 closeset 值:fig.update_layout(hovermode="x")fig.update_traces(hoverinfo = 'x+y')