I have the following three lists:
JavaScript
x
4
1
list 1: ['Dog','Cat','Mouse']
2
list 2: [['3','8','9'],['6','7','8'],['3','8','9']]
3
list 3: [['11:03:15','11:05:15',11:08:15'],['11:03:15','11:05:15',11:08:15'],['11:03:15','11:05:15',11:08:15']]
4
I was wondering how I can take these 3 lists and iterate through them to get lists
so the first plot would be plotting dog as title with y value as the first list in 2d list 2 and the x value would the first list in 2d list 3. This would iterate for each value.
My idea is I think to zip these 3 lists like
result = zip(list1,list2,list3)
and then somehow iterate to do something like this but Python says zip object is not subscriptable
JavaScript
1
3
1
for i,j,k in range(1, 60):
2
df.plot(kind = 'line',x=list1[i], y=list2[j], ax = ax, label =list3[k], figsize=(16,8))
3
Could anyone explain how I can do this??
Advertisement
Answer
It seems to me that you want something fairly straightforward:
JavaScript
1
15
15
1
import matplotlib.pyplot as plt
2
3
list1 = ['Dog', 'Cat', 'Mouse']
4
list2 = [['3', '8','9'],
5
['6', '7', '8'],
6
['3', '8', '9']]
7
list3 = [['11:03:15', '11:05:15', '11:08:15'],
8
['11:03:15', '11:05:15', '11:08:15'],
9
['11:03:15', '11:05:15', '11:08:15']]
10
11
for title, y, x in zip(list1, list2, list3):
12
fig, ax = plt.subplots() # Create a new figure.
13
ax.set_title(title) # Set the title to dog/cat/mouse.
14
ax.plot(x, y) # Plot the data.
15