ValueError: The data property of a figure may only be assigned a list or tuple that contains a .....

Posted Data+Science+Insight

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ValueError: The data property of a figure may only be assigned a list or tuple that contains a .....相关的知识,希望对你有一定的参考价值。

ValueError: The data property of a figure may only be assigned a list or tuple that contains a permutation of a subset of itself.

问题:

import plotly as py  
# 导入plotly库并命名为py
import plotly.graph_objs as go
import pandas as pd

fig = go.Figure()

# -------------pre def
pyplt = py.offline.plot

df = pd.read_csv(r'dat/appl.csv', index_col=['date'], parse_dates=['date'])

trace = go.Ohlc(
    x=df.index,
    open=df.open,
    high=df.high,
    low=df.low,
    close=df.close,
)

fig['data'] = [trace]
# fig.add_trace(trace)

fig['layout'].update(
    xaxis=go.XAxis(
        autorange=True,
        mirror='all',
        gridcolor='rgb(180, 180, 180)',
        showline=True,  # 画出 X 轴那条线
        showgrid=True,
        tickangle=-60,
        categoryorder="category ascending",
        type='category'),
    yaxis=go.YAxis(
        autorange=True,
        gridcolor='rgb(180, 180, 180)',
    ),
)

pyplt(fig, filename=r'tmp/ohlc_filter_time.html')

 解决:

# fig.add_trace(trace)

import plotly as py  
# 导入plotly库并命名为py
import plotly.graph_objs as go
import pandas as pd

fig = go.Figure()

# -------------pre def
pyplt = py.offline.plot

df = pd.read_csv(r'dat/appl.csv', index_col=['date'], parse_dates=['date'])

trace = go.Ohlc(
    x=df.index,
    open=df.open,
    high=df.high,
    low=df.low,
    close=df.close,
)

# fig['data'] = [trace]
fig.add_trace(trace)

fig['layout'].update(
    xaxis=go.XAxis(
        autorange=True,
        mirror='all',
        gridcolor='rgb(180, 180, 180)',
        showline=True,  # 画出 X 轴那条线
        showgrid=True,
        tickangle=-60,
        categoryorder="category ascending",
        type='category'),
    yaxis=go.YAxis(
        autorange=True,
        gridcolor='rgb(180, 180, 180)',
    ),
)

pyplt(fig, filename=r'tmp/ohlc_filter_time.html')

完整错误:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-12-9eb74208098f> in <module>
     19 )
     20 
---> 21 fig['data'] = [trace]
     22 # fig.add_trace(trace)
     23 

D:\\anaconda\\lib\\site-packages\\plotly\\basedatatypes.py in __setitem__(self, prop, value)
    682 
    683             if prop == "data":
--> 684                 self.data = value
    685             elif prop == "layout":
    686                 self.layout = value

D:\\anaconda\\lib\\site-packages\\plotly\\basedatatypes.py in __setattr__(self, prop, value)
    719         if prop.startswith("_") or hasattr(self, prop):
    720             # Let known properties and private properties through
--> 721             super(BaseFigure, self).__setattr__(prop, value)
    722         else:
    723             # Raise error on unknown public properties

D:\\anaconda\\lib\\site-packages\\plotly\\basedatatypes.py in data(self, new_data)
   1003             err_msg = err_header
   1004 
-> 1005             raise ValueError(err_msg)
   1006 
   1007         # ### Check for duplicates in assignment ###

ValueError: The data property of a figure may only be assigned 
a list or tuple that contains a permutation of a subset of itself.

参考:plotly

参考:How to update figure data?

以上是关于ValueError: The data property of a figure may only be assigned a list or tuple that contains a .....的主要内容,如果未能解决你的问题,请参考以下文章

paddle报ValueError: The type of data we are trying to retrieve does not match the type

paddle报ValueError: The type of data we are trying to retrieve does not match the type

ValueError: The data property of a figure may only be assigned a list or tuple that contains a .....

python pandas进行条件筛选时出现ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a

ValueError: The number of elements in ‘fill‘ does not match the number of bands of the image (3 != 4

加载 tf.keras 模型,ValueError: The two structure don't have the same nested structure