Python Plotly:滑块不刷新散点图

Python Plotly:滑块不刷新散点图,python,plotly,Python,Plotly,我将使用自己的数据从plotly()开始学习滑块动画打印教程,该教程位于底部。我的场景基本上是从应用程序的用户处收集数据。我有一个月(5月)的数据,每天每小时记录用户频率。我想使用一个滑块来获得从第1天到第31天的一系列值,并通过绘图来显示每个特定日期每小时的唯一值 我的问题是:我只得到第一天,但滑块的值正在正确更新。修复了旧问题,现在我有了另一个问题:现在数据的一个步骤,图形显示了每一个步骤 我的代码: 我也无法摆脱右边的彩色标记 编辑1:添加的dfMay表格 编辑2:更改问题,添加新绘图 补

我将使用自己的数据从plotly()开始学习滑块动画打印教程,该教程位于底部。我的场景基本上是从应用程序的用户处收集数据。我有一个月(5月)的数据,每天每小时记录用户频率。我想使用一个滑块来获得从第1天到第31天的一系列值,并通过绘图来显示每个特定日期每小时的唯一值

我的问题是:我只得到第一天,但滑块的值正在正确更新。修复了旧问题,现在我有了另一个问题:现在数据的一个步骤,图形显示了每一个步骤

我的代码: 我也无法摆脱右边的彩色标记

编辑1:添加的dfMay表格 编辑2:更改问题,添加新绘图 补充图片:


修复了与滑块相关的问题。我遵循了另一个生动的教程


为了快速解决问题,请将代码与包含问题的示例数据共享?如果可能,完整的代码@NarenMurali数据很敏感,所以我不能这么做。我没有收到任何错误消息。我会放一张dfMay的截图。
# dMay to DataFrame
dfMay = pd.DataFrame({key :dMay[key] for key in list(dMay.keys())})
for i, df in enumerate([dfMay], 1):
    df.columns = [str(col_name)[6:].format(i) for col_name in df.columns]

keys = list(map(lambda x: str(x), dfMay.keys())) # Slider values - days
from plotly.grid_objs import Grid, Column
listOfCols = []
for col in keys:
    listOfCols.append(Column(dfMay[col], col))
grid = Grid(listOfCols)
py.grid_ops.upload(grid, 'Testing'+str(time.time()), auto_open=False)

# Animated Plot
figure = {
    'data': [],
    'layout': {},
    'frames': []
}

# fill in most of layout
figure['layout']['xaxis'] = {'range': [0, 23], 'title': 'Zaman (saat)'}
figure['layout']['yaxis'] = {'title': 'Kullanıcı Sayısı', 'type': 'linear'}
figure['layout']['hovermode'] = 'closest'
figure['layout']['sliders'] = {
    'args': [
        'transition', {
            'duration': 400,
            'easing': 'cubic-in-out'
        }
    ],
    'initialValue': '0',
    'plotlycommand': 'animate',
    'values': list(range(24)),
    'visible': True
}
figure['layout']['updatemenus'] = [
    {
        'buttons': [
            {
                'args': [None, {'frame': {'duration': 500, 'redraw': True},
                         'fromcurrent': True, 'transition': {'duration': 300, 'easing': 'quadratic-in-out'}}],
                'label': 'Play',
                'method': 'animate'
            },
            {
                'args': [[None], {'frame': {'duration': 0, 'redraw': True}, 'mode': 'immediate',
                'transition': {'duration': 0}}],
                'label': 'Pause',
                'method': 'animate'
            }
        ],
        'direction': 'left',
        'pad': {'r': 10, 't': 87},
        'showactive': False,
        'type': 'buttons',
        'x': 0.1,
        'xanchor': 'right',
        'y': 0,
        'yanchor': 'top'
    }
]

sliders_dict = {
    'active': 0,
    'yanchor': 'top',
    'xanchor': 'left',
    'currentvalue': {
        'font': {'size': 20},
        'prefix': 'Zaman:',
        'visible': True,
        'xanchor': 'right'
    },
    'transition': {'duration': 300, 'easing': 'cubic-in-out'},
    'pad': {'b': 10, 't': 50},
    'len': 0.9,
    'x': 0.1,
    'y': 0,
    'steps': []
}

# make data
start = 0
for day in keys:

data_dict = {
    'x': list(range(24)),
    'y': list(dfMay[day]),
    'mode': 'markers',
    'marker': {
        'sizemode': 'area',
        'sizeref': 200000,
        'size': 20
    },
    'name': day
}
figure['data'].append(data_dict)

# make frames
for day in keys:
    frame = {'data': [], 'name': str(day)}
    data_dict = {
        'x': list(range(24)),
        'y': list(dfMay[day]),
        'mode': 'markers',
        'text': list(dfMay[day]),
        'marker': {
            'sizemode': 'area',
            'sizeref': 200000,
            'size': 20
        },
        'name': day,
    }
    frame['data'].append(data_dict)

    figure['frames'].append(frame)
    slider_step = {'args': [
        [day],
        {'frame': {'duration': 1000, 'redraw': True},
         'mode': 'immediate',
       'transition': {'duration': 1000}}
     ],
     'label': day,
     'method': 'animate'}
    sliders_dict['steps'].append(slider_step)

    
figure['layout']['sliders'] = [sliders_dict]
print('Done')
plot(figure)
plotData=[dict(type='scatter',
          x=list(range(24)),
          y=test_data[:0],
          mode='markers',
          marker=dict(size=10, color='red')
              )
     ]

frames=[dict(data=[dict(y=test_data[:,k])],
             traces=[0],
             name=f'{k+1}',
             layout=dict(yaxis=dict(range=[-1, test_data[:, k].max()+100]))) for k in range(31)]

sliders=[dict(steps= [dict(method= 'animate',
                           args= [[ f'{k+1}'],
                                  dict(mode= 'e',
                                  frame= dict( duration=1000, redraw= False ),
                                           transition=dict( duration= 0)
                                          )
                                    ],
                            label=f' {k+1}'
                             ) for k in range(31)], 
                transition= dict(duration= 30 ),
                x=0,#slider starting position  
                y=0, 
                currentvalue=dict(font=dict(size=12), 
                                  prefix='Day: ', 
                                  visible=True, 
                                  xanchor= 'center'
                                 ),  
                len=1.0,
                active=1) #slider length)

           ]

axis_style=dict(showline=True,
               mirror=True,
               zeroline=False,
               ticklen=4)

layout=dict(title='Mayıs-Günlük Kullanıcı Sayıları',
            width=900,
            height=600,
            autosize=False,
            xaxis=dict(axis_style, dtick=1, tit='s' title='Zaman (saat)', **dict(range=[0,24])),
            yaxis=dict(axis_style, title='Kullanıcı Sayısı',autorange=False),
            #plot_bgcolor="rgba(66,134,244, 0.2)",
            shapes= [dict(
                        # Sabah
                        type= 'rect',
                        xref= 'x',
                        yref= 'paper',
                        x0= '0',
                        y0= 0,
                        x1= '8',
                        y1= 1,
                        fillcolor= 'rgba(66, 134, 244, 0.5)',
                        opacity= 0.2,
                        line= dict(width= 0)
                    ),
                     # Oglen
                    dict(
                        type= 'rect',
                        xref= 'x',
                        yref= 'paper',
                        x0= '8',
                        y0= 0,
                        x1= '16',
                        y1= 1,
                        fillcolor= '#rgba(255, 252, 117,1)',
                        opacity= 0.2,
                        line= dict(width=0)
                    ),
                      # Aksam
                    dict(
                        type= 'rect',
                        xref= 'x',
                        yref= 'paper',
                        x0= '16',
                        y0= 0,
                        x1= '24',
                        y1= 1,
                        fillcolor= 'rgba(2, 0, 168, 1)',
                        opacity= 0.2,
                        line= dict(width=0)
                    )
            ],
            hovermode='closest',
            updatemenus=[dict(type='buttons', showactive=True,
                                y=0,
                                x=1.15,
                                xanchor='right',
                                yanchor='top',
                                pad=dict(t=0, r=10),
                                buttons=[dict(label='Play',
                                              method='animate',
                                              args=[None, 
                                                    dict(frame=dict(duration=4000, 
                                                                    redraw=True),
                                                         transition=dict(duration=4000),
                                                         fromcurrent=True,
                                                         mode='immediadate'
                                                        )
                                                   ]
                                             ),
                                         dict(label='Pause',
                                              method='animate',
                                              args=[[None], 
                                                    dict(frame=dict(duration=0, 
                                                                    redraw=False),
                                                         transition=dict(duration=30),
                                                         fromcurrent=True,
                                                         mode='immediate'
                                                        )
                                                   ]
                                             )
                                        ]
                               )
                          ],
              sliders=sliders
           )

# Animated Plot
figure = {
    'data': plotData,
    'layout': layout,
    'frames': frames
}  
fig=dict(data=plotData, frames=frames, layout=layout)
fig['data'][0].update(mode='markers+lines',
                     line=dict(width=1.5, color='blue'))
plot(fig, auto_open=False)