这感觉像是一个非常开放的问题,关于为什么你想要绘制重复的系列,你最终是如何得到重复的。但我们现在暂且不谈。如果您最终会得到1000 重复项,我会为每个系列使用不同的线宽,并在'rgba(0, 0, 255, {a}' 中使用非常低的不透明度a。您也可以为每一行使用不同的不透明度,但您不必这样做。如果您在df_dupe 中有重复值并且在df 中有一些独特的系列,这是一种方法。 Dupes 以blue 的阴影显示。如果您可以使用此功能,我很乐意提供其他详细信息。
剧情:
完整代码:
from plotly.subplots import make_subplots
import plotly.graph_objs as go
import pandas as pd
import numpy as np
# random data
np.random.seed(123)
frame_rows = 100
frame_cols = 3
frame_columns = ['V_'+str(e) for e in list(range(frame_cols+1))]
df=pd.DataFrame()
dupe_rows = 100
dupe_cols = 1000
dupe_columns = ['D_'+str(e) for e in list(range(dupe_cols+1))]
df_dupe=pd.DataFrame()
# rng = range(fra)
# dupe data
for i, col in enumerate(dupe_columns):
df_dupe[col]=np.sin(np.arange(0,frame_rows/10, 0.1))#*np.random.uniform(low=0.1, high=0.99))
# non-dupe data
for i, col in enumerate(frame_columns):
df[col]=np.sin(np.arange(0,frame_rows/10, 0.1))*((i+1)/5)
fig = go.Figure()
# calculations for opacity, colors and widths for duped lines
N = len(dupe_columns)
opac = []
colors = []
max_width = 50
widths = []
# colors and widths
for i, col in enumerate(dupe_columns):
a = (1/N)*(i+1)
opac.append(a)
colors.append('rgba(0,0,255, '+str(a)+')')
#widths2 = N/(i+1)
widths.append(max_width/(i+1)**(1/2))
# line and colors for duplicated values
fig = go.Figure()
for i, col in enumerate(dupe_columns):
fig.add_traces(go.Scatter(x=df_dupe.index, y = df_dupe[col], mode = 'lines',
# line_color = colors[i],
line_color ='rgba(0,0,255, 0.05)',
line_width = widths[i]))
# highlight one of the dupe series
fig.add_traces(go.Scatter(x=df_dupe.index, y = df_dupe[col], mode = 'lines',
line_color ='rgb(0,0,255)',
line_width = 3))
# compare dupes to some other series
for i, col in enumerate(frame_columns[-3:]):
fig.add_traces(go.Scatter(x=df.index, y = df[col], mode = 'lines',
# line_color = colors[i],
# line_width = widths[i]
))
fig.update_yaxes(range=[-1.3, 1.3])
fig.show()