error using plotly on pycharm

Viewed 13627
    import plotly.plotly as py
    from plotly.offline import download_plotlyjs, init_notebook_mode, plot,iplot
    import plotly.graph_objs as go
    init_notebook_mode(connected=True)


        data = dict(type = 'choropleth',
            locations = ['AZ','CA','NY'],
            locationmode = 'USA-states',
            colorscale= 'Portland',
            text= ['text1','text2','text3'],
            z=[1.0,2.0,3.0],
            colorbar = {'title':'Colorbar Title'})

        layout = dict(geo = {'scope':'usa'})

    choromap = go.Figure(data = [data],layout = layout)

    py.iplot(choromap)

I've been trying to figure out a way to use plotly on pycharm. When I use the code above, it gives me this error.

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

Hi this is my first question on stackoverflow, apologies if my question isn't structured well. Any advice over asking it properly , is greatly appreciated.

3 Answers
import plotly
from plotly.offline import init_notebook_mode
import plotly.graph_objs as go
plotly.offline.init_notebook_mode(connected=True)


data = dict(type = 'choropleth',
            locations = ['AZ','CA','NY'],
            locationmode = 'USA-states',
            colorscale= 'Portland',
            text= ['text1','text2','text3'],
            z=[1.0,2.0,3.0],
            colorbar = {'title':'Colorbar Title'})

layout = dict(geo = {'scope':'usa'})

choromap = go.Figure(data = [data],layout = layout)

plotly.offline.plot(choromap)

This will definitely work for sure for offline plotting .

You need to authenticate yourself in plotly.

  1. Create an account on plotly.
  2. Go to https://plot.ly/python/getting-started/

There is a description in the link from point 2 on how to set up your credentials:

import plotly

plotly.tools.set_credentials_file(username='DemoAccount', api_key='lr1c37zw81')

Related