我刚刚尝试了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.
实际上,我想构建一种具有一些笔触的游标,并将其值写在上面。所以任何人都可以帮助我,我会很感激。预先感谢。
答案 0 :(得分:3)
您可以将Plotly设置为在联机或脱机模式下工作。 要在线工作,您需要一个用户名
要离线工作,只需将代码编辑为
import plotly
import plotly.graph_objs as go
from plotly.offline import *
...
...
plotly.offline.plot(fig, filename='gauge-meter-chart.html')