版本:python3.6、anaconda3(64bit)
问题描述:使用plotly跑下来没有报错,但是也不显示图。即使加上plt.show(),也无济于事,还请大神指点,谢谢。
代码如下:
import plotly.plotly as plt
import plotly.offline as pltoff
from plotly.graph_objs import *
def line_plots(name):
dataset = {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'y': [5, 4, 1, 3, 11, 2, 6, 7, 19, 20],
'z': [12, 9, 0, 0, 3, 25, 8, 17, 22, 5]}
data_g = []
tr_x = Scatter(
x=dataset['x'],
y=dataset['y'],
name='y'
)
data_g.append(tr_x)
tr_z = Scatter(
x=dataset['x'],
y=dataset['z'],
name='z'
)
data_g.append(tr_z)
layout = Layout(title="line plots", xaxis={'title': 'x'}, yaxis={'title': 'value'})
fig = Figure(data=data_g, layout=layout)
pltoff.plot(fig, filename=name)
plt.show()
因为你只是写了函数,没有运行你的函数啊,删掉plt.show()这句错误语法,在最后一行加入line_plots('test')就可以了
import plotly.plotly as plt
import plotly.offline as pltoff
from plotly.graph_objs import *
def line_plots(name):
dataset = {'x': [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
'y': [5, 4, 1, 3, 11, 2, 6, 7, 19, 20],
'z': [12, 9, 0, 0, 3, 25, 8, 17, 22, 5]}
data_g = []
tr_x = Scatter(
x=dataset['x'],
y=dataset['y'],
name='y'
)
data_g.append(tr_x)
tr_z = Scatter(
x=dataset['x'],
y=dataset['z'],
name='z'
)
data_g.append(tr_z)
layout = Layout(title="line plots", xaxis={'title': 'x'}, yaxis={'title': 'value'})
fig = Figure(data=data_g, layout=layout)
pltoff.plot(fig, filename=name)
line_plots('test)
顶一下,不要沉下去了111111111
好复杂啊,表示看不懂啊,英语是不是要有基础
我加了这个就可以显示了
import chart_studio
chart_studio.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81')