我正在用 Plotly 制作一个“Rolling Dice”项目。在此之前,我使用以下命令安装 Plotly: $ python -m pip install --user plotly
当我运行“from plotly.gragh_objs import Bar, layout”时,我收到错误消息: 'ModuleNotFoundError: 没有名为 'plotly.gragh_objs' 的模块
我尝试升级 pip,但它不起作用。任何人都知道问题出在哪里。
我的代码如下:
from plotly.gragh_objs import Bar, Layout
from ploty import offline
from dice import Die
die = Die()
results = []
for roll_num in range(1000):
result = die.roll()
results.append(result)
frequencies = []
for value in range(1, die.num_sides+1):
frequency = results.count(value)
frequencies.append(frequency)
x_values = list(range(1, die.num_sides+1))
data = [Bar(x=x_values, y=frequencies)]
x_axis_config = {'title':'Result'}
y_axis_config = {'title':'Frequency of Result'}
my_layout = Layout(title='Results of rolling one D6 1000 times',
xaxis=x_axis_config, yaxis=y_axis_config)
offline.plot({'data':data, 'layout':my_layout}, filename='d6.html')
答案 0 :(得分:0)
导入代码应该如下:
from plotly.graph_objects import Bar, Layout
from plotly import offline