For Loop on Plotly Python -


i trying replace

fig.append_trace(trace1, 1, 1) fig.append_trace(trace2, 2, 1) 

with loop code

totalplot = 2 x = ['trace%s'%(item + 1) item in range(totalplot)] y = [(item + 1) item in range(totalplot)] z = totalplot * [1]  i, j, k in zip(x, y, z):     fig.append_trace(i, j, k) 

so more scalable add more figures. however, loop code keeps returning 'typeerror: 'str' object not support item assignment'. did wrong?

here code similar 1 plotly:

from plotly import tools import plotly.plotly py import plotly.graph_objs go  trace1 = go.scatter(     x=[1, 2, 3],     y=[4, 5, 6] ) trace2 = go.scatter(     x=[20, 30, 40],     y=[50, 60, 70], )  fig = tools.make_subplots(rows=2, cols=1)   # ----- loop here ------- start fig.append_trace(trace1, 1, 1) fig.append_trace(trace2, 2, 1) # ----- loop here ------- end  fig['layout'].update(height=600, width=600, title='i <3 subplots') py.iplot(fig, filename='make-subplots') 

in code looks trace1 kind of array-like data structure:

trace1 = go.scatter(     x=[1, 2, 3],     y=[4, 5, 6] ) 

so imagine when call fig.append_trace(trace1, 1, 1) it's adding element array-like structure, first parameter.

however in reimplementation, you've turned trace data string:

x = ['trace%s'%(item + 1) item in range(totalplot)] ... i, j, k in zip(x, y, z):     fig.append_trace(i, j, k) 

here i element of x in turn string 'trace%s'%(item + 1). cannot append element string. python strings immutable. when call append_trace naturally error here not being able want strings.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -