python - Invalid 'figure_or_data' argument when plotting a chart with traces appended through loops - plotly -


i put code can inserted loop, in order plot line chart, appending trace values of each column in dataframe. have been struggling while, , cannot quite figure out how keys in plotly figures , layout objects should called.

import pandas pd import plotly.plotly py plotly import tools, utils plotly.graph_objs import *   d = {'one' : pd.series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']), 'three' : pd.series([1, 2, 3, 4, 5], index=['a', 'b', 'c', 'd','e'])} df = pd.dataframe(d)  print(df.head())  data = []  column in df:      trace = scatter(     x = df.index,      y = df[column],     mode = 'lines',     line = line(         color='#ffd700',         width=1         ),     name = column     )     data.append([trace])   layout = dict(     title= 'room ambient temperatures (with range slider , selectors)',      yaxis=dict(         range=[20,30],         showgrid=true,         zeroline=true,         showline=false,     ),  ) fig = dict(data=data, layout=layout)    #fig = figure(data=data, layout=layout)      chart_url = py.plot(fig, filename = 'test/_t_line_chart', auto_open=false) 

error is:

invalid entry found in 'data' @ index, '0' path error: ['data'][0] valid items 'data' @ path ['data'] under parents ['figure']:     ['contour', 'box', 'scatter3d', 'bar', 'mesh3d', 'histogram', 'surface',     'pie', 'histogram2d', 'scattergeo', 'scattergl', 'scattermapbox',     'scatterternary', 'candlestick', 'ohlc', 'scatter', 'area',     'histogram2dcontour', 'choropleth', 'heatmap', 'pointcloud'] entry should subclass dict. 

any idea why?

just replace data.append([trace]) data.append(trace).

what end passing right [[trace1],[trace2],...[trace_n]]instead of [trace1, trace2,...,trace_n]


site note: might want @ cufflinks too. make easy:

import cufflinks cf  df.iplot(layout=layout) 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -