2013-07-06 26 views
8

Sembra semplice ma non riesco a disegnare un grafico X-Y con "punti" in DataFrame panda. Voglio mostrare il subid come "Segno" su X Y Grafico con X come età e Y come fdg.Panda semplice X trama Y

Codice finora

mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22, 'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}] 

df = pandas.DataFrame(mydata) 

DataFrame.plot(df,x="age",y="fdg") 

show() 

enter image description here

risposta

9

df.plot() accetterà matplotlib kwargs. Vedere la docs

mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22, 
      'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}] 

df = pandas.DataFrame(mydata) 
df = df.sort(['age']) # dict doesn't preserve order 
df.plot(x='age', y='fdg', marker='.') 

enter image description here

Rileggendo la tua domanda, penso si potrebbe effettivamente chiedere per un grafico a dispersione.

import matplotlib.pyplot as plt 
plt.scatter(df['age'], df['fdg']) 

Avere uno sguardo ai matplotlib docs.

+0

Grazie per entrambe la risposta. Comunque come mettere il nome di "subid" con i punti. – LonelySoul

+1

http://stackoverflow.com/questions/15910019/annotate-data-points-while-plotting-from-pandas-dataframe/15911372#15911372 –

+0

@DanAllan purtroppo dice "Disegna" non definito. A quale modulo appartiene ... – LonelySoul

1

Provare a seguire per un diagramma a dispersione.

import pandas 
from matplotlib import pyplot as plt 

mydata = [{'subid': 'B14-111', 'age': 75, 'fdg': 3}, {'subid': 'B14-112', 'age': 22, 
      'fdg': 2}, {'subid': 'B14-112', 'age': 40, 'fdg': 5}] 

df = pandas.DataFrame(mydata) 
x,y = [],[] 

x.append (df.age) 
y.append (df.fdg) 
fig = plt.figure() 
ax = fig.add_subplot(111) 
ax.plot(y,x,'o-') 
plt.show() 
Problemi correlati