Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error using plotly on pycharm

    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.

like image 683
sai Avatar asked Jul 24 '17 17:07

sai


People also ask

Does plotly work in Pycharm?

The best way to create and view Plotly Figures in PyCharm is using Jupyter Notebooks instead of regular Python Files. To create a Jupyter Notebook in Pycharm, Select File -> New and Select New File. Add the filename ending with .

Why plotly is not working?

If you are encountering problems using plotly with Dash please first ensure that you have upgraded dash to the latest version, which will automatically upgrade dash-core-components to the latest version, ensuring that Dash is using an up-to-date version of the Plotly. js rendering engine for plotly .

How do I add plotly to Pycharm?

In Pycharm you have to download it. Go to File --> Settings -->Project --> Project Interpreter --> on the plus right site--> search for your module and download it! Thats it!!

Why is plotly offline?

Setting for Offline Plotting Plotly allows you to generate graphs offline and save them in local machine. The plotly. offline. plot() function creates a standalone HTML that is saved locally and opened inside your web browser.


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

like image 86
Ankit Kamboj Avatar answered Oct 20 '22 11:10

Ankit Kamboj


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

like image 6
justnpT Avatar answered Oct 20 '22 11:10

justnpT