如何循环遍历列表以创建多个图 Python
How to loop through lists to create multiple plots Python
我有以下三个列表:
list 1: ['Dog','Cat','Mouse']
list 2: [['3','8','9'],['6','7','8'],['3','8','9']]
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']]
我想知道如何获取这 3 个列表并遍历它们以获取列表
所以第一个图将绘制狗作为标题,y 值作为 2d 列表 2 中的第一个列表,x 值将作为 2d 列表 3 中的第一个列表。这将迭代每个值。
我的想法是将这 3 个列表压缩为
result = zip(list1,list2,list3)
然后以某种方式迭代做这样的事情但是 Python 说 zip object 不可订阅
for i,j,k in range(1, 60):
df.plot(kind = 'line',x=list1[i], y=list2[j], ax = ax, label =list3[k], figsize=(16,8))
谁能解释一下我该怎么做?
在我看来,你想要的东西相当简单:
import matplotlib.pyplot as plt
list1 = ['Dog', 'Cat', 'Mouse']
list2 = [['3', '8','9'],
['6', '7', '8'],
['3', '8', '9']]
list3 = [['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']]
for title, y, x in zip(list1, list2, list3):
fig, ax = plt.subplots() # Create a new figure.
ax.set_title(title) # Set the title to dog/cat/mouse.
ax.plot(x, y) # Plot the data.
我有以下三个列表:
list 1: ['Dog','Cat','Mouse']
list 2: [['3','8','9'],['6','7','8'],['3','8','9']]
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']]
我想知道如何获取这 3 个列表并遍历它们以获取列表
所以第一个图将绘制狗作为标题,y 值作为 2d 列表 2 中的第一个列表,x 值将作为 2d 列表 3 中的第一个列表。这将迭代每个值。
我的想法是将这 3 个列表压缩为
result = zip(list1,list2,list3)
然后以某种方式迭代做这样的事情但是 Python 说 zip object 不可订阅
for i,j,k in range(1, 60):
df.plot(kind = 'line',x=list1[i], y=list2[j], ax = ax, label =list3[k], figsize=(16,8))
谁能解释一下我该怎么做?
在我看来,你想要的东西相当简单:
import matplotlib.pyplot as plt
list1 = ['Dog', 'Cat', 'Mouse']
list2 = [['3', '8','9'],
['6', '7', '8'],
['3', '8', '9']]
list3 = [['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']]
for title, y, x in zip(list1, list2, list3):
fig, ax = plt.subplots() # Create a new figure.
ax.set_title(title) # Set the title to dog/cat/mouse.
ax.plot(x, y) # Plot the data.