2017-04-23 2 views
2

angezeigt habe ich ein Array: die ersten Elemente dieser Arrays auf der y-Achse der Anzeige mit matplotlibeine graphische Darstellung der ersten Elemente des Arrays

[[5, 6, 9,...], [3, 7, 7,...], [8, 4, 9,...],...] 

Wie kann ich eine Handlung zu machen? x-Achse kann nur 1, 2, 3, ... sein

So die Handlung hätte Werte:

x -> y 
1 -> 5 
2 -> 3 
3 -> 8 ... 

Antwort

3

Nur erste Spalte eines Arrays auswählen und mit plt.plot Befehl wie hier plotten:

import matplotlib.pylab as plt 
import numpy as np 

# test data 
a = np.array([[5, 6, 9], [3, 7, 7], [8, 4, 9]]) 
print(a[:,0]) # result is [5 3 8] 

# plot the line 
plt.plot(a[:,0]) 
plt.show() 

enter image description here

0

Sie können das erste Element der Listen holen und dann eine andere Liste erstellen, indem diese Elemente angehängt wird.

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() 

enter image description here

Verwandte Themen