首页 > 解决方案 > 使用 simple_plotly 时如何解决“NameError: name 'plotly_version' is not defined”?

问题描述

我正在尝试为我的硕士论文代码绘制地图。到目前为止,我只是在尝试https://nbviewer.jupyter.org/github/e2nIEE/pandapower/blob/develop/tutorials/plotly_maps.ipynb中的一个示例,所以我想一切都应该正常工作。但是,当尝试使用函数“simple_plotly”时,会出现 NameError。我怎样才能让它发挥作用?

这是我得到错误的行:

from pandapower.plotting.plotly import simple_plotly
from pandapower.networks import mv_oberrhein
net = mv_oberrhein()
simple_plotly(net, on_map=True, projection='epsg:31467')

错误

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-8-9381f16ca1ad> in <module>()
      9 
     10 net = mv_oberrhein()
---> 11 simple_plotly(net, on_map=True, projection='epsg:31467')

~/miniconda3/lib/python3.6/site-packages/pandapower/plotting/plotly/simple_plotly.py in simple_plotly(net, respect_switches, use_line_geodata, on_map, projection, map_style, figsize, aspectratio, line_width, bus_size, ext_grid_size, bus_color, line_color, trafo_color, ext_grid_color)
    116         **ext_grid_color** (String, 'yellow') - External Grid Color. Init is yellow
    117     """
--> 118     version_check()
    119     # create geocoord if none are available
    120     if 'line_geodata' not in net:

~/miniconda3/lib/python3.6/site-packages/pandapower/plotting/plotly/traces.py in version_check()
     33 
     34 def version_check():
---> 35     if version.parse(plotly_version) < version.parse("3.1.1"):
     36         raise UserWarning("Your plotly version {} is no longer supported.\r\n"
     37                           "Please upgrade your python-plotly installation, "

NameError: name 'plotly_version' is not defined

标签: pythonplotlyjupyter

解决方案


出现此错误是因为未安装 plotly,使用 pip 安装 ploty 即可。

Pip install plotly

推荐阅读