2013-07-06 8 views
8

シンプルに見えますが、私はパンダのDataFrameに "dots"を含むX-Yチャートを描くことができません。 subidをX YチャートでXとし、Xを年齢とし、Yをfdgとしたいとします。パンダ簡単なX Yプロット

コードは、これまで

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

答えて

9

df.plot()はmatplotlibのkwargsを受け入れます。 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

が再びあなたの質問を読んでください、私はあなたが実際に散布を求めるかもしれないと思っています。

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

matplotlibドキュメントをご覧ください。

+0

両方の答えに感謝します。しかし、どのように "subid"の名前をドットでつけるか。 – LonelySoul

+1

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

+0

@DanAllan残念ながら、「描画」は定義されていません。どのモジュールに属していますか... – LonelySoul

1

散布図では次のようにしてください。

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() 
関連する問題