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

Viewed 19

I have x:size(271,1,1),y:size(271,70,1). Then I have to attribute 70 sets of numbers(size(271,1,1)) to each line the color varies with its magnitude. My way is

for mm in range(0, 70):
    plt.plot(x, y[mm])
    plt.ylim(min, max)
    plt.xlim(0, x[-1])
norm = plt.Normalize(-0.5,0.5)
for ii in range(0,70):
    points = np.array([a, y[ii]]).T.reshape(-1, 1, 2)
    tmp = np.concatenate([points[:-1],points[1:]],axis=1)
    lc = LineCollection(tmp,cmap='viridis',norm=norm)
    lc.set_array(color[ii])
    line = axs.add_collection(lc)
    plt.colorbar(line, ax=axs)

The above can't show multicolored line. An error shows' AttributeError: 'tuple' object has no attribute 'add_collection''

For example,my goal is if there are three lists x = [0,1,2];y = [[2,3,4],[4,5,6]];color = [[0.1,0.3,0.5],[1,0.4,0.6]] as the following figure for continuously multicolored line. example

1 Answers
Related