gpt4 book ai didi

python - 这个例子 Plotly 散点图不起作用,你能告诉我为什么吗?

转载 作者:太空宇宙 更新时间:2023-11-03 21:18:52 24 4
gpt4 key购买 nike

这是代码,来自https://plot.ly/python/line-and-scatter/

import plotly.plotly as py
import plotly.graph_objs as go

# Create random data with numpy
import numpy as np

N = 100
random_x = np.linspace(0, 1, N)
random_y0 = np.random.randn(N)+5
random_y1 = np.random.randn(N)
random_y2 = np.random.randn(N)-5

# Create traces
trace0 = go.Scatter(
x = random_x,
y = random_y0,
mode = 'markers',
name = 'markers'
)
trace1 = go.Scatter(
x = random_x,
y = random_y1,
mode = 'lines+markers',
name = 'lines+markers'
)
trace2 = go.Scatter(
x = random_x,
y = random_y2,
mode = 'lines',
name = 'lines'
)

data = [trace0, trace1, trace2]
py.iplot(data, filename='scatter-mode')

当我将其复制并粘贴到 jupyter 笔记本中时,出现以下错误:

PlotlyError:因为您在调用中没有提供“file_id”,所以我们假设您正在尝试从网址中获取数字。您提供了网址“”,我们希望它以“https://plot.ly”开头'。运行此函数的帮助以获取更多信息。

整个错误:

Aw, snap! We didn't get a username with your request.

Don't have an account? https://plot.ly/api_signup

Questions? accounts@plot.ly
---------------------------------------------------------------------------
PlotlyError Traceback (most recent call last)
<ipython-input-7-70bd62361f83> in <module>()
27
28 data = [trace0, trace1, trace2]
---> 29 py.iplot(data, filename='scatter-mode')

c:\users\appdata\local\programs\python\python37-32\lib\site-packages\plotly\plotly\plotly.py in iplot(figure_or_data, **plot_options)
162 embed_options['height'] = str(embed_options['height']) + 'px'
163
--> 164 return tools.embed(url, **embed_options)
165
166

c:\users\appdata\local\programs\python\python37-32\lib\site-packages\plotly\tools.py in embed(file_owner_or_url, file_id, width, height)
394 else:
395 url = file_owner_or_url
--> 396 return PlotlyDisplay(url, width, height)
397 else:
398 if (get_config_defaults()['plotly_domain']

c:\users\appdata\local\programs\python\python37-32\lib\site-packages\plotly\tools.py in __init__(self, url, width, height)
1438 def __init__(self, url, width, height):
1439 self.resource = url
-> 1440 self.embed_code = get_embed(url, width=width, height=height)
1441 super(PlotlyDisplay, self).__init__(data=self.embed_code)
1442

c:\users\appdata\local\programs\python\python37-32\lib\site-packages\plotly\tools.py in get_embed(file_owner_or_url, file_id, width, height)
299 "'{1}'."
300 "\nRun help on this function for more information."
--> 301 "".format(url, plotly_rest_url))
302 urlsplit = six.moves.urllib.parse.urlparse(url)
303 file_owner = urlsplit.path.split('/')[1].split('~')[1]

PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.
Run help on this function for more information.

最佳答案

由于代码中的这些小更改,您应该能够使其工作:

import plotly

plotly.offline.plot(data, filename='basic-scatter')

关于python - 这个例子 Plotly 散点图不起作用,你能告诉我为什么吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54469599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com