【发布时间】:2017-04-23 08:40:50
【问题描述】:
我有一个数组:
[[5, 6, 9,...], [3, 7, 7,...], [8, 4, 9,...],...]
如何使用 matplotlib 在 y 轴上显示这些数组的第一个元素? x 轴可以是 1, 2, 3,...
所以情节会有价值:
x -> y
1 -> 5
2 -> 3
3 -> 8 ...
【问题讨论】:
标签: python python-2.7 numpy matplotlib
我有一个数组:
[[5, 6, 9,...], [3, 7, 7,...], [8, 4, 9,...],...]
如何使用 matplotlib 在 y 轴上显示这些数组的第一个元素? x 轴可以是 1, 2, 3,...
所以情节会有价值:
x -> y
1 -> 5
2 -> 3
3 -> 8 ...
【问题讨论】:
标签: python python-2.7 numpy matplotlib
您可以获取列表的第一个元素,然后通过附加这些元素来创建另一个列表。
import matplotlib.pyplot as plt
oldList = [[5, 6, 9,...], [3, 7, 7,...], [8, 4, 9,...],...]
newList= []
for element in oldList:
newList.append(element[0]) #for every element, append first member of that element
print(newList) #not necessary line, just for convenience
plt.plot(newList)
plt.show()
【讨论】: