How do you plot a graph consisting of extracted entries from a nested list? -
i have nested list such that;
nested_list = [[4, 3, 0], [6, 8, 7], [3, 1, 8], [2, 1, 3], [9, 9, 3], ...]
which has 100 entries.
i need plot graph of first elements of each sub-list where
sub_list_1 = [4, 6, 3, 2, 9, ...]
against third elements of each sub-list where
sub_list_2 = [0, 7, 8, 3, 3, ...]
over sub-lists, have no idea how this.
this have tried:
k=0 while k<=100: x=nested_list[0][0][k] y=nested_list[k][0][0] k=+1 plt.plot(x,y) plt.axis('image') plt.show()
this not work however.
you need build 2 new lists. can list comprehensions:
x = [sub[0] sub in nested_list] y = [sub[2] sub in nested_list] plt.plot(x,y)
your code tried access 1 level of nesting many (you can address nested_list[k][0]
, not nested_list[k][0][0]
) or tried index first value of first nested list index k
. did not build new lists; rebound x
, y
k
times.
Comments
Post a Comment