2017-11-09 6 views
0

の色を設定するために使用ルックアップ辞書、私は次のようにパンダのデータフレームからソースデータとの散布図のポイントに色をしようとしています:パイソン - pyplot散乱

x = [5,7,12,0,19,56,40,16,36,17,81,50] 
y = [20,26,37,40,8,63,13,28,47,91,26,2] 
letter = ['A','B','C','D','E','F','E','B','A','C','F','D'] 
df = pd.DataFrame({'x' : x, 'y' : y,'letter' : letter}) 

私も、ルックアップを設定しています私が使用して、ポイントの色を設定するのですかpyplot散乱関数の色引数を(C =)、使用

letter_col = {'A':'blue', 'B':'red', 'C':'green', 'D':'yellow', 'E':'orange', 'F':'pink'} 

:「手紙」列内のどの値に割り当てられている色を決定する辞書、 letter_col?

+0

を渡したいです= letter_col [df.y]) '? –

答えて

0

私はちょうどあなたがC、 `plt.scatter(X = df.x、Y = df.yを試してみたのデータフレーム内color列を作成し、その後、散乱関数に

x = [5,7,12,0,19,56,40,16,36,17,81,50] 
y = [20,26,37,40,8,63,13,28,47,91,26,2] 
letter_col = {'A':'blue', 'B':'red', 'C':'green', 'D':'yellow', 'E':'orange', 'F':'pink'} 
letter = ['A','B','C','D','E','F','E','B','A','C','F','D'] 
colors = map(lambda x: letter_col.get(x, 'black'), letter) 
df = pd.DataFrame({'x' : x, 'y' : y,'letter' : letter, 'color': colors})