Black Lives Matter. Please consider donating to Black Girls Code today.
Dash HoloViews is now available! Check out the docs.

Issue with basic graph - Help

Can anyone help me solving the following issue? Code does not work in spyder or jupyter

Code adapted to spyder bt using print statements. I get same error in jupyter notebook and spyder:

import plotly.offline as pyo
import plotly.plotly as py
from plotly.graph_objs import * #I get a message: "unable to obtain undefined names"
import plotly.graph_objs as go #therefore, I tried getting the names of objects
go.Scatter
go.Layout

import pandas as pd
from pandas import DataFrame

#allowing to see plots as we create them - Initially I was using jupyter notebook but didn’t work either
pyo.offline.init_notebook_mode()

dict1 = {‘key1’ : ‘value1’, ‘key2’: 5}

trace1 = {‘type’ : ‘scatter’,
‘x’ : [0,1,2,3,4,5,6,7,8,9],
‘y’ : [0,1,2,3,4,5,6,7,8,9],
‘name’ : ‘trace1’,
‘mode’ : ‘lines’
}

layout = {‘title’ : ‘My first Plotly line chart’,
‘xaxis’ : { ‘tile’ : ‘X Values’},
‘yaxix’ : { ‘tile’ : ‘Y Values’}}

data = go.Data([trace1])

print(data)

fig = go.Figure(data = data, layout = layout)

print(fig)

//////
Error I get:

File “”, line 1, in
fig = Figure(data = data, layout = layout)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 1163, in init
super(Figure, self).init(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 432, in setitem
value = self._value_to_graph_object(key, value, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 543, in _value_to_graph_object
_parent=self, _parent_key=key)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 799, in create
return PlotlyDict(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 432, in setitem
value = self._value_to_graph_object(key, value, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 543, in _value_to_graph_object
_parent=self, _parent_key=key)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 799, in create
return PlotlyDict(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 428, in setitem
raise exceptions.PlotlyDictKeyError(self, path)

PlotlyDictKeyError: ‘tile’ is not allowed in ‘xaxis’

Path To Error: [‘layout’][‘xaxis’][‘tile’]

Valid attributes for ‘xaxis’ at path [‘layout’][‘xaxis’] under parents [‘figure’, ‘layout’]:

['anchor', 'autorange', 'autotick', 'backgroundcolor', 'calendar',
'categoryarray', 'categoryarraysrc', 'categoryorder', 'color',
'constrain', 'constraintoward', 'domain', 'dtick', 'exponentformat',
'fixedrange', 'gridcolor', 'gridwidth', 'hoverformat', 'layer',
'linecolor', 'linewidth', 'mirror', 'nticks', 'overlaying', 'position',
'range', 'rangemode', 'rangeselector', 'rangeslider', 'scaleanchor',
'scaleratio', 'separatethousands', 'showaxeslabels', 'showbackground',
'showexponent', 'showgrid', 'showline', 'showspikes', 'showticklabels',
'showtickprefix', 'showticksuffix', 'side', 'spikecolor', 'spikedash',
'spikemode', 'spikesides', 'spikethickness', 'tick0', 'tickangle',
'tickcolor', 'tickfont', 'tickformat', 'ticklen', 'tickmode',
'tickprefix', 'ticks', 'ticksuffix', 'ticktext', 'ticktextsrc',
'tickvals', 'tickvalssrc', 'tickwidth', 'title', 'titlefont', 'type',
'visible', 'zeroline', 'zerolinecolor', 'zerolinewidth']

Run <xaxis-object>.help('attribute') on any of the above.
’’ is the object at [‘layout’][‘xaxis’]

runfile(‘C:/Users/clbel/gitRepos/Plotly/Test.py’, wdir=‘C:/Users/clbel/gitRepos/Plotly’)

[{‘type’: ‘scatter’, ‘x’: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ‘y’: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], ‘name’: ‘trace1’, ‘mode’: ‘lines’}]

Traceback (most recent call last):

File “”, line 1, in
runfile(‘C:/Users/clbel/gitRepos/Plotly/Test.py’, wdir=‘C:/Users/clbel/gitRepos/Plotly’)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”, line 880, in runfile
execfile(filename, namespace)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py”, line 102, in execfile
exec(compile(f.read(), filename, ‘exec’), namespace)

File “C:/Users/clbel/gitRepos/Plotly/Test.py”, line 46, in
fig = go.Figure(data = data, layout = layout)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 1163, in init
super(Figure, self).init(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 432, in setitem
value = self._value_to_graph_object(key, value, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 543, in _value_to_graph_object
_parent=self, _parent_key=key)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 799, in create
return PlotlyDict(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 432, in setitem
value = self._value_to_graph_object(key, value, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 543, in _value_to_graph_object
_parent=self, _parent_key=key)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 799, in create
return PlotlyDict(*args, **kwargs)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 377, in init
self.setitem(key, val, _raise=_raise)

File “C:\Users\clbel\AppData\Local\Continuum\Anaconda3\lib\site-packages\plotly\graph_objs\graph_objs.py”, line 428, in setitem
raise exceptions.PlotlyDictKeyError(self, path)

PlotlyDictKeyError: ‘tile’ is not allowed in ‘xaxis’

Path To Error: [‘layout’][‘xaxis’][‘tile’]

Valid attributes for ‘xaxis’ at path [‘layout’][‘xaxis’] under parents [‘figure’, ‘layout’]:

['anchor', 'autorange', 'autotick', 'backgroundcolor', 'calendar',
'categoryarray', 'categoryarraysrc', 'categoryorder', 'color',
'constrain', 'constraintoward', 'domain', 'dtick', 'exponentformat',
'fixedrange', 'gridcolor', 'gridwidth', 'hoverformat', 'layer',
'linecolor', 'linewidth', 'mirror', 'nticks', 'overlaying', 'position',
'range', 'rangemode', 'rangeselector', 'rangeslider', 'scaleanchor',
'scaleratio', 'separatethousands', 'showaxeslabels', 'showbackground',
'showexponent', 'showgrid', 'showline', 'showspikes', 'showticklabels',
'showtickprefix', 'showticksuffix', 'side', 'spikecolor', 'spikedash',
'spikemode', 'spikesides', 'spikethickness', 'tick0', 'tickangle',
'tickcolor', 'tickfont', 'tickformat', 'ticklen', 'tickmode',
'tickprefix', 'ticks', 'ticksuffix', 'ticktext', 'ticktextsrc',
'tickvals', 'tickvalssrc', 'tickwidth', 'title', 'titlefont', 'type',
'visible', 'zeroline', 'zerolinecolor', 'zerolinewidth']

Run <xaxis-object>.help('attribute') on any of the above.
’’ is the object at [‘layout’][‘xaxis’]

I am able to run the code only for “data”, but once I run either:
fig = go.Figure(data = data, layout = layout)
fig = Figure(data = data, layout = layout)

I get again the same error as indicated above.

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

go.Scatter
go.Layout

import pandas as pd
from pandas import DataFrame
pyo.offline.init_notebook_mode()

dict1 = {‘key1’ : ‘value1’, ‘key2’: 5}

trace1 = {‘type’ : ‘scatter’,
‘x’ : [0,1,2,3,4,5,6,7,8,9],
‘y’ : [0,1,2,3,4,5,6,7,8,9],
‘name’ : ‘trace1’,
‘mode’ : ‘lines’
}

layout = {‘title’ : ‘My first Plotly line chart’,
‘xaxis’ : { ‘tile’ : ‘X Values’},
‘yaxix’ : { ‘tile’ : ‘Y Values’}}

data = go.Data([trace1])
print(data)

##fig does not work! anyone knows why?
#fig = go.Figure(data = data, layout = layout)
#print(fig)