无法更新python中的plotty图表

时间:2019-01-24 12:59:24

标签: python plotly

我有图表,每次更新时我都想在jupyter笔记本中进行更新。图表越来越平淡,但是当我尝试更新时却没有生效。

图表需要每秒更新一次新值。我尝试了所有建议,但无法确定我是否缺少某些东西或不可能

我也尝试使用FigueChart。


import pandas as pd
import plotly.offline as pt
from plotly import tools
import plotly.graph_objs as go
import numpy

pt.init_notebook_mode()

data = {
    'date': [
        '2019-01-21 13:30:00',
        '2019-01-21 13:45:00',
        '2019-01-21 14:00:00',
        '2019-01-21 14:15:00',
        '2019-01-21 14:30:00',
        '2019-01-21 14:45:00',
        '2019-01-21 15:00:00',
        '2019-01-21 15:15:00',
        '2019-01-21 15:30:00',
        '2019-01-21 15:45:00'
    ],
    'open': [
        6770.00,
        6763.00,
        6767.00,
        6762.75,
        6759.75,
        6747.75,
        6753.75,
        6752.25,
        6753.00,
        6754.50
    ],
    'high': [
        6771.50,
        6768.75,
        6767.25,
        6766.25,
        6760.25,
        6754.75,
        6755.25,
        6754.50,
        6754.50,
        6760.00
    ],
    'low': [
        6763.25,
        6762.00,
        6760.00,
        6758.00,
        6747.00,
        6746.75,
        6750.75,
        6751.00,
        6749.50,
        6754.25
    ],
    'close': [
        6763.25,
        6767.25,
        6763.00,
        6759.75,
        6747.50,
        6754.25,
        6752.00,
        6752.00,
        6754.00,
        6759.25
    ],
    'EMA50': [
        6772.018804,
        6771.831793,
        6771.485448,   
        6771.025234,   
        6770.102676,   
        6769.481002,   
        6768.795473,   
        6768.136827,   
        6767.582441,   
        6767.255679   
    ]
}

df = pd.DataFrame(data=data)


candlestick_df = df[['date', 'open', 'high', 'low', 'close','EMA50']]



layout = go.Layout(
    xaxis=dict(
        rangeslider=dict(
            visible=False
        )
    )
)

trace_list = []

trace = go.Candlestick(x=candlestick_df.date,
                       open=candlestick_df.open,
                       high=candlestick_df.high,
                       low=candlestick_df.low,
                       close=candlestick_df.close,
                       text=candlestick_df.close)
ema50_trace = go.Scatter(
            x=candlestick_df.date,
            y=candlestick_df.EMA50,
            name='EMA50',
            mode='lines')


trace_list.append(trace)
trace_list.append(ema50_trace)


fig = go.Figure(data=trace_list, layout=layout)

pt.iplot(fig)

## Following is not running
fig.data[1].y = [
        6737.840856,
        6738.133484,
        6738.380912,
        6738.593540,
        6738.682161,
        6738.837065,
        6738.968039,
        6739.097711,
        6739.245992,
        6739.445037
    ] 

理想情况下,应该是EMA行具有更新后的值,但仍会出现旧行

0 个答案:

没有答案