2016-12-21 8 views
-1

私は以下のフォーマットのパンダデータフレームを持っています。私はこのコードを試みたが、完璧な結果が得られていないようです0と1パンダデータフレームの値の散布図

Distance ClusterAssigned 
    23  1 
    35  1 
    20  1 
    264  0 
    830  0 

ため、おそらく異なる色で、ClusterAssignedに基づいて、このデータをプロットしようとしています。

groups = dfprintscatter.groupby('ClusterAssigned') 

import matplotlib.pyplot as plt 

fig, ax = plt.subplots() 
ax.margins(0.05) 
for name, group in groups: 
     ax.plot(group.Distance, group.ClusterAssigned, marker='o', linestyle='', ms=5, label=name) 
ax.legend() 

plt.show() 
+1

使用していますか? – piRSquared

答えて

3

あなたはmatplotlibの中scatter機能を使用する必要があり、そこにループする必要がない、または任意のグループ化を行います。

x = np.arange(len(dfprintscatter)) 
y = dfprintscatter.Distance 
c = dfprintscatter.ClusterAssigned 
plt.scatter(x, y, c=c, marker='o') 

seabornあなたは完璧な結果を考慮しないものを

import seaborn as sns 
sns.lmplot(x=np.arange(len(dfprintscatter)), y='Distance', hue='ClusterAssigned', fit_reg=False) 
+0

ありがとう、これは私が実際に探していたものです。 plt.scatterでラベルを割り当てることはできますか? – user3447653

+0

ラベルを正しいものにするにはループする必要があります。シーボンを使う方がはるかに簡単です。 –

+0

私はseabornで試してみましたが、 "regplot()に予想外のキーワード引数 'hue'があります" – user3447653