0

I just tried the code from https://plot.ly/python/gauge-charts/ but even though its not working. can u please guide me where i am going wrong ? I am new bee to python and plotly as well. Here's the code :

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')

Error message is :

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.

Actually i want to built a guage having some stroke and their values written above them. so Anyone can help me ,i would be thankful. Thanks in advance.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
SAMRIDHI JAIN
  • 52
  • 1
  • 1
  • 7

1 Answers1

8

You can set up Plotly to work in online or offline mode. To work in online you need a username

To work in offline just edit the code as

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

...
...

plotly.offline.plot(fig, filename='gauge-meter-chart.html')
Sunitha
  • 11,777
  • 2
  • 20
  • 23
  • thanks it's working and may i know how can i embed this in my gui. I dont need new window pop-up. @Sunitha – SAMRIDHI JAIN Jun 21 '18 at 10:35
  • try plotly.offline.iplot(fig, filename='gauge-meter-chart'). – Sunitha Jun 21 '18 at 10:38
  • The document Suggests "Use plotly.offline.plot() to create and standalone HTML that is saved locally and opened inside your web browser. Use plotly.offline.iplot() when working offline in a Jupyter Notebook to display the plot in the notebook." – Sunitha Jun 21 '18 at 10:39