Seabornの散布図でプロットを色分けしたいと思い次のコードを書きました。
python
1sns.scatterplot(x=data['block'], y=data[col], hue=data2[col], s=100) 2plt.savefig(graph_path + col+r".svg")
おおむね狙い通りの図が描けたのですが、色味が気に入らなかったので次のように書き換えました。
python
1colp = sns.blend_palette(['grey', 'yellow', 'red'], 3) 2sns.scatterplot(x=data['block'], y=data[col], hue=data2[col], palette=colp, s=100) 3plt.savefig(graph_path + col+r".svg") 4・ 5・ 6・ 7ValueError: The palette list has the wrong number of colors.
パレットの色数が気に入らないといわれたので、3を1~4まで、および"なし"で変化させましたが同じ結果でした。
ちなみに data2[col] がとりうるあたいは、0,1,2のどれかです。
どうしたら良いでしょうか?
どうやら失敗しているパターンでは、print(set(data2[col]))の結果が{0,1}のようです。
0,1,2のどれが含まれているか含まれていないかにかかわらず、
0->grey
1->yellow
2->red
となるようにしたいのですが。
回答1件
あなたの回答
tips
プレビュー