对于带有绘图(离线)的极地图动画,过渡未显示

时间:2019-07-23 14:36:34

标签: python plotly plotly-python

我正在尝试使用离线模式下的绘图使极谱图平滑旋转。在examples available in the docs之后,我通过创建一个带有“动画”方法的按钮并将过渡时间设置为> 0 ms的值来完成此操作。

使用散点图类型图而不是条形图时发生了相同的问题,但是该动画确实适用于非极性散点图。

import plotly.graph_objs as go
import plotly.offline as offline
import pandas as pd
import numpy as np
offline.init_notebook_mode()

#some data to plot:
df = pd.DataFrame({'artist':['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'],
                            'birth': pd.to_datetime(pd.Series(['1990-04-01T00:00:00.000000000', '1945-12-01T00:00:00.000000000',
                                      '1955-01-01T00:00:00.000000000', '1956-01-01T00:00:00.000000000',
                                      '1976-12-01T00:00:00.000000000', '1930-05-01T00:00:00.000000000',
                                      '1942-01-01T00:00:00.000000000', '1936-11-01T00:00:00.000000000',
                                      '1971-12-01T00:00:00.000000000', '1952-12-01T00:00:00.000000000'])), 
                            'death': pd.to_datetime(pd.Series(['2012-04-01T00:00:00.000000000', '2015-12-01T00:00:00.000000000',
                                      '2010-01-01T00:00:00.000000000', '2017-01-01T00:00:00.000000000',
                                      '2016-12-01T00:00:00.000000000', '2017-05-01T00:00:00.000000000',
                                      '2010-01-01T00:00:00.000000000', '2015-11-01T00:00:00.000000000',
                                      '2014-12-01T00:00:00.000000000', '2013-12-01T00:00:00.000000000']))} )

#creating the barplot:
shift = df['birth'] - pd.datetime(1970, 1 ,1) 
trace = {
    'name': "to", 
    'r': (df['death']- shift).dt.date, 
    'theta': np.linspace(0,360,11),
    'base':df['birth'].dt.date,
    'type': 'barpolar'
}
data = [trace]

nsteps = 20
tracedicts = [] 
start_thetas = np.linspace(0,360,nsteps)
for i in start_thetas:
    tracedicts.append(trace.copy())
    tracedicts[-1]['theta'] = np.linspace(i,360+i,11)

frames = [{'data': [tracei]} for tracei in tracedicts]

layout = {
    'polar':{
        'angularaxis':{
            'visible': False,
        },
        'radialaxis':{  
            'showgrid': True,
            'type': 'date',
            'hoverformat': '%m-%Y',
        }
    },
    'updatemenus': [{
        'type': 'buttons',
        'x': 0.1,
        'y': 0,
        'buttons':[{'label':'Play', 'method':'animate',
                    'args':[None, {'frame':{'duration':600, 'redraw':True}, 
                                   'transition':{'duration':400},
                                   'fromcurrent':True,
                                   'easing': 'linear'}]}]
    }],
} 

fig = go.Figure(data=data, layout=layout, frames = frames)
offline.iplot(fig,auto_play=False)

动画可以显示不同的帧,但过渡效果不起作用。 这是不是所有极坐标图和/或条形图都不存在的功能?

(您还将注意到,我设置了'redraw':True-这是因为否则动画只有在最后设置auto_play=True时才起作用。)

0 个答案:

没有答案