AttributeError: 'tuple' object has no attribute 'append'

import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.graph_objs as go

Create quiver figure

fig = ff.create_quiver(x, y, u, v,
scale=.25,
arrow_scale=.4,
name=‘quiver’,
line=dict(width=1))

Create points

points = go.Scatter(x=[-.7, .75], y=[0,0],
mode=‘markers’,
marker=dict(size=12),
name=‘points’)

Add points to figure

fig[‘data’].append(points)#???
How to solve it?

Hi there,

Tuples in Python are immutable, i.e., they can’t be changed (and therefore appended to) like lists can. That’s why you’re getting the error that you have.

When you create the quiver figure, where are x, y, u, and v defined? If you want to plot the points you mentioned, then try doing something like this: https://plot.ly/python/quiver-plots/#reference

Let me know if that helps!

It looks like the example code you’re using has become deprecated since plotly 3.0 has switched to representing Figure.data as a tuple instead of a list.

Use fig.add_trace(points) instead of fig['data'].append(points).

For more information about the changes in plotly 3.0.0 see this page.

@dxf7608 First you should define/read from a file/compute the lists of the same length, x, y, u, v.

printing fig = ff.create_quiver(...) as in the code below, you see that fig.data[0] is already created.

To append a new trace you should define a new figure as in this example:

import plotly.plotly as py
import plotly.figure_factory as ff
import plotly.graph_objs as go
import numpy as np

x=[1.7, 2, 1.87]
y=[1.3, 1.8, 0.9]
u=[-0.15, 0.3, -0.49]
v=[-0.2, 0.13, 0.58]


fig = ff.create_quiver(x, y, u, v,
                       scale=.25,
                       arrow_scale=.30,
                       name='quiver',
                       line=dict(width=1))

print(fig)
xx=2*np.random.rand(5)
yy=0.2+1.5*np.random.rand(5)
trace=dict(type='scatter',
          x=xx,
          y=yy,
          mode='markers',
          marker=dict(color='red',
                     size=6)
          )

#define a new figure as an instance of go.FigureWidget:
fw=go.FigureWidget(data=[fig.data[0], trace], layout=fig.layout)
#or fig_new=go.Figure(data=[fig.data[0], trace], layout=fig.layout))
#and plot fig_new
fw.layout.update(width=600, height=500,
                 plot_bgcolor='rgb(240,240,240)')
fw

new_fig