0

我尝试重现在plotlyPython 中使用多个子图进行绘图的示例,该示例在此处作为第一个示例发布:“Python 中的子图”。我在 Jupyter notebook 中工作,plotly版本:3.10.0,Python版本:3.6.3。

运行该示例后:

from plotly.subplots import make_subplots
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

## Allow to generate plotly plots inline in notebook
init_notebook_mode(connected=True)

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)
fig.update_layout(height=600, width=800, title_text="Subplots")
iplot(fig)

我得到了ValueError

ValueError: 
plotly.subplots.make_subplots may only be used in the
v4_subplots _plotly_future_ mode.  To try it out, run
>>> from _plotly_future_ import v4_subplots
before importing plotly.

然后我from _plotly_future_ import v4_subplots在导入的最顶部添加。我清理了输出,用来%restet清理所有的变量,甚至刷新了笔记本,但是头条的代码:

from _plotly_future_ import v4_subplots 
from plotly.subplots import make_subplots 
import plotly.graph_objs as go from plotly.offline import download_plotlyjs, 
init_notebook_mode, plot, iplot
# (...)

现在的结果是ImportError

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-14-d2ad52c99588> in <module>
----> 1 from _plotly_future_ import v4_subplots
      2 from plotly.subplots import make_subplots
      3 import plotly.graph_objs as go
      4 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
      5 

c:\users\karasma6\appdata\local\continuum\anaconda3\envs\actigrapy\lib\site-packages\_plotly_future_\v4_subplots.py in <module>
      2 from _plotly_future_ import _future_flags, _assert_plotly_not_imported
      3 
----> 4 _assert_plotly_not_imported()
      5 _future_flags.add('v4_subplots')

c:\users\karasma6\appdata\local\continuum\anaconda3\envs\actigrapy\lib\site-packages\_plotly_future_\__init__.py in _assert_plotly_not_imported()
      9     if 'plotly' in sys.modules:
     10         raise ImportError("""\
---> 11 The _plotly_future_ module must be imported before the plotly module""")
     12 
     13 

ImportError: The _plotly_future_ module must be imported before the plotly module

如何解决?

4

1 回答 1

1

您可能必须重新启动内核:仅刷新笔记本是不够的。

也就是说,第 4 版现已推出,因此您最好的选择是升级 :)

于 2019-07-28T12:41:32.440 回答