我想把图例放在散点图中,我使用了c
参数对类进行分组并分配颜色。
我的代码如下:
peral = data[['SiO2a', 'A/CNK','Type', 'Code']]**
Locality SiO2a A/CNK Type Code
0 CN 71.58 1.13 Rhyolite 7
1 CN 71.76 1.14 Rhyolite 7
2 CN 70.95 1.08 Rhyolite 7
3 CN 70.79 1.14 Rhyolite 7
4 CN 71.69 1.12 Rhyolite 7
... ... ... ... ... ...
158 Pairique 63.74 1.09 mafic inclusion 11
159 Pairique 61.77 1.09 mafic inclusion 11
160 Huayra Huasi 65.43 1.10 mafic inclusion 11
161 Huayra Huasi 61.14 1.26 mafic inclusion 11
162 Huayra Huasi 62.53 1.21 mafic inclusion 11
plt.figure(figsize=(10,10))
plt.scatter(peral['SiO2a'], peral['A/CNK'], c=peral['Code'])
plt.legend()
plt.ylim(0.8,2.5)
plt.xlabel('SiO2 %wt')
plt.ylabel('A/CNK')
列'Code'
是将LabelEncoder
应用于列'Type'
的结果,我想用列'Type'
的原始名称构造图例
有人知道怎么做吗
您可以在
'Type'
值上循环,并将每个值作为筛选器应用:完整代码
相关问题 更多 >
编程相关推荐