2
私はseaborn
プロットを持っています。色を注釈したい(好ましくは凡例と同様に色マッピングを使用します)。 regplot
にはcolor
メソッドがあることがわかります。私はこれをどのように利用するのか分かりません。Seaborn.regplot(Python 3)内のポイントに色を割り当て/マップします
私はcolor
メソッドに{index : color}
をマッピングし、データフレーム自体に色の値を追加する辞書を与えるか、いくつかの方法を試しました。
どのようにポイントを割り当てた色でマップできますか?
np.random.seed(0)
# Create dataframe
DF_0 = pd.DataFrame(np.random.random((100,2)), columns=["x","y"])
# Label to colors
D_idx_color = {**dict(zip(range(0,25), ["#91FF61"]*25)),
**dict(zip(range(25,50), ["#BA61FF"]*25)),
**dict(zip(range(50,75), ["#91FF61"]*25)),
**dict(zip(range(75,100), ["#BA61FF"]*25))}
DF_0["color"] = pd.Series(list(D_idx_color.values()), index=list(D_idx_color.keys()))
# Plot
sns.regplot(data=DF_0, x="x", y="y") #works, plot below
# sns.regplot(data=DF_0, x="x", y="y", color="color") # doesn't work
# ValueError: to_rgb: Invalid rgb arg "color"
# could not convert string to float: 'color'
# sns.regplot(data=DF_0, x="x", y="y", color=DF_0["color"]) # doesn't work
# ValueError: to_rgb: Invalid rgb arg "('#91FF61', '#91FF61', ...
# sns.regplot(data=DF_0, x="x", y="y", color=D_idx_color) # doesn't work
# ValueError: to_rgb: Invalid rgb arg "(0, 1, 2, ...
あなたは異なる色で、これらの点のいくつかを重ねてプロットして、色の凡例を持つようにしたいですか? – cphlewis