Python 绘图子批次:索引器:元组索引超出范围

Python 绘图子批次:索引器:元组索引超出范围,python,python-3.x,plotly,Python,Python 3.x,Plotly,我正在尝试运行Plotly教程以在()上生成子图: 我得到以下错误: --------------------------------------------------------------------------- IndexError Traceback (most recent call last) in 1 from plotly.subplots import make_subplots 2

我正在尝试运行Plotly教程以在()上生成子图:

我得到以下错误:

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
 in 
      1 from plotly.subplots import make_subplots
      2 fig = make_subplots(rows=2, cols=1)
----> 3 fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
      4 fig.add_trace(go.Bar(y=[2, 1, 3]), row=2, col=1)
      5 fig.show()

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in add_trace(self, trace, row, col)
   1070         # ----------------
   1071         for key_path_str, v in restyle_data.items():
-> 1072 
   1073             # Track whether any of the new values are cause a change in
   1074             # self._data

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in add_traces(self, data, rows, cols)
   1153         # In batch mode
   1154         # -------------
-> 1155         # Add key_path_str/val to saved batch edits
   1156         else:
   1157             if trace_index not in self._batch_trace_edits:

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in _set_trace_grid_position(self, trace, row, col)
   1254 
   1255     @staticmethod
-> 1256     def _set_in(d, key_path_str, v):
   1257         """
   1258         Set a value in a nested dict using a key path string

IndexError: tuple index out of range

你知道怎么纠正吗?提前谢谢。

只需将
列表作为
元组传递即可:

从plotly.subplot导入make_subplot
###下次指定它
导入plotly.graph_对象作为go
图=生成子图(行=2,列=1)
图添加轨迹(go.Scatter(y=元组([4,2,1]),mode=“line”),行=1,列=1)
图add_轨迹(go.Bar(y=元组([2,1,3])),行=2,列=1)
图2(图3)
结果:
什么是
go.
?对不起,这是故意的<代码>导入plotly.graph_对象为go
感谢您的快速回复。当我运行你的代码时,我仍然得到了错误。更新到Plotly 4.0使我能够运行它。在我更新之后,您的代码可以正常工作,但原始代码也可以正常工作。谢谢你帮我弄清真相。
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
 in 
      1 from plotly.subplots import make_subplots
      2 fig = make_subplots(rows=2, cols=1)
----> 3 fig.add_trace(go.Scatter(y=[4, 2, 1], mode="lines"), row=1, col=1)
      4 fig.add_trace(go.Bar(y=[2, 1, 3]), row=2, col=1)
      5 fig.show()

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in add_trace(self, trace, row, col)
   1070         # ----------------
   1071         for key_path_str, v in restyle_data.items():
-> 1072 
   1073             # Track whether any of the new values are cause a change in
   1074             # self._data

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in add_traces(self, data, rows, cols)
   1153         # In batch mode
   1154         # -------------
-> 1155         # Add key_path_str/val to saved batch edits
   1156         else:
   1157             if trace_index not in self._batch_trace_edits:

~\AppData\Local\Continuum\anaconda3\envs\quantlib\lib\site-packages\plotly\basedatatypes.py in _set_trace_grid_position(self, trace, row, col)
   1254 
   1255     @staticmethod
-> 1256     def _set_in(d, key_path_str, v):
   1257         """
   1258         Set a value in a nested dict using a key path string

IndexError: tuple index out of range