iplot()不工作。为什么?如果它需要帐户?

2024-05-14 20:35:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚尝试了https://plot.ly/python/gauge-charts/中的代码,但即使它不起作用。你能告诉我哪里出错了吗? 我是Python的新蜜蜂,而且情节也很复杂。 代码如下:

import plotly.plotly as py

import plotly.graph_objs as go
from plotly.offline import *

base_chart = {
    "values": [40, 10, 10, 10, 10, 10, 10],
    "labels": ["-", "0", "20", "40", "60", "80", "100"],
    "domain": {"x": [0, .48]},
    "marker": {
        "colors": [
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)',
            'rgb(255, 255, 255)'
        ],
        "line": {
            "width": 1
        }
    },
    "name": "Gauge",
    "hole": .4,
    "type": "pie",
    "direction": "clockwise",
    "rotation": 108,
    "showlegend": False,
    "hoverinfo": "none",
    "textinfo": "label",
    "textposition": "outside"
}
meter_chart = {
    "values": [50, 10, 10, 10, 10, 10],
    "labels": ["Log Level", "Debug", "Info", "Warn", "Error", "Fatal"],
    "marker": {
        'colors': [
            'rgb(255, 255, 255)',
            'rgb(232,226,202)',
            'rgb(226,210,172)',
            'rgb(223,189,139)',
            'rgb(223,162,103)',
            'rgb(226,126,64)'
        ]
    },
    "domain": {"x": [0, 0.48]},
    "name": "Gauge",
    "hole": .3,
    "type": "pie",
    "direction": "clockwise",
    "rotation": 90,
    "showlegend": False,
    "textinfo": "label",
    "textposition": "inside",
    "hoverinfo": "none"
}
layout = {
    'xaxis': {
        'showticklabels': False,
        'autotick': False,
        'showgrid': False,
        'zeroline': False,
    },
    'yaxis': {
        'showticklabels': False,
        'autotick': False,
        'showgrid': False,
        'zeroline': False,
    },
    'shapes': [
        {
            'type': 'path',
            'path': 'M 0.235 0.5 L 0.24 0.65 L 0.245 0.5 Z',
            'fillcolor': 'rgba(44, 160, 101, 0.5)',
            'line': {
                'width': 0.5
            },
            'xref': 'paper',
            'yref': 'paper'
        }
    ],
    'annotations': [
        {
            'xref': 'paper',
            'yref': 'paper',
            'x': 0.23,
            'y': 0.45,
            'text': '50',
            'showarrow': False
        }
    ]
}

# we don't want the boundary now
base_chart['marker']['line']['width'] = 0

fig = {"data": [base_chart, meter_chart],
       "layout": layout}
# fig.show()

py.iplot(fig, filename='gauge-meter-chart')

错误消息是:

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
Traceback (most recent call last):
  File "graph.py", line 101, in <module>
    py.iplot(fig, filename='gauge-meter-chart')
  File "C:\Users\Sam\Anaconda2\envs\py35\lib\site-packages\plotly\plotly\plotly.py", line 164, in iplot
    return tools.embed(url, **embed_options)
  File "C:\Users\Sam\Anaconda2\envs\py35\lib\site-packages\plotly\tools.py", line 396, in embed
    return PlotlyDisplay(url, width, height)
  File "C:\Users\Sam\Anaconda2\envs\py35\lib\site-packages\plotly\tools.py", line 1440, in __init__
    self.embed_code = get_embed(url, width=width, height=height)
  File "C:\Users\Sam\Anaconda2\envs\py35\lib\site-packages\plotly\tools.py", line 301, in get_embed
    "".format(url, plotly_rest_url))
plotly.exceptions.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.

实际上,我想建立一个有一些笔划和他们的价值写在上面的语言。所以任何人都可以帮我,我会很感激的。提前谢谢。


Tags: inpyfalseurlplotlinechartly
1条回答
网友
1楼 · 发布于 2024-05-14 20:35:36

可以将Plotly设置为在联机或脱机模式下工作。 要在网上工作,你需要一个用户名

要脱机工作,只需将代码编辑为

import plotly
import plotly.graph_objs as go
from plotly.offline import *

...
...

plotly.offline.plot(fig, filename='gauge-meter-chart.html')

相关问题 更多 >

    热门问题