次のようなコードを書いてFig.1を得ました。
python
1import seaborn as sns 2import matplotlib.pylab as plt 3 4x=["a","b","c","d","e","f"] 5y=[1,2,3,4,5,6] 6h=[0,0,-1,-1,+1,+1] 7s=[10,20,40,10,20,40] 8sns.scatterplot(x=x, y=y, hue=h, size=s, legend="full")
Fig. 1
概ね望み通りなのですが凡例のラベルが気に入らないので次のようにしました。
python
1import seaborn as sns 2import matplotlib.pylab as plt 3 4x=["a","b","c","d","e","f"] 5y=[1,2,3,4,5,6] 6h=[0,0,-1,-1,+1,+1] 7s=[10,20,40,10,20,40] 8sns.scatterplot(x=x, y=y, hue=h, size=s, legend="full") 9plt.legend(labels=["-","/","+","0","1","2"], ncol=2, title="H_Type S_Type")
Fig. 2
凡例の - と 0 のマーカーが + と 2 のマーカーと同じものになっています。
どうすれば修正できますか?
※新たなる問題。
※s や h の値によって失敗する例。
python
1import seaborn as sns 2import matplotlib.pylab as plt 3 4x=["a","b","c","d","e","f"] 5y=[1,2,3,4,5,6] 6h=[0,0,0,0,0,0] 7s=[10,20,10,10,20,20] 8sizes = {x: x for x in s} 9colp = {-1:'#1F3FDF', 0:'#222222', +1:'#DF1F3F'} 10ax=sns.scatterplot(x=x, y=y, hue=h, size=s, sizes=sizes, palette=colp, legend="full") 11handles, labels = ax.get_legend_handles_labels() 12ax.legend(handles=handles, labels=["-","/","+","0","1","2"], ncol=2, title="H_Type S_Type")

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/09/07 04:49
2022/09/07 06:16
2022/09/08 08:48
2022/09/09 06:52