1

我正在尝试通过使用 swarmplot 创建单维聚类来使用 power bi 和 python。

一切都很完美,除了我分配给它的色阶。这是我的代码。X="Centros"(传中)和 hue="Equipos"(球队)。

import matplotlib.pyplot as plt

#fig. ax = plt.subplots()

sns.set(style="whitegrid", palette="muted")
sns.swarmplot(x="Centros", hue="Equipos", palette=["red","coral","linegreen","forestgreen"],s=13, data=dataset,hue_order=['00-20','20-40','40-60','60-80','80-100'] )

plt.show()```

[enter image description here][1]


  [1]: https://i.stack.imgur.com/CnAqH.png
4

1 回答 1

0

您需要使用色调的类别将字典构建到调色板参数中......例如: sns.swarmplot(x='centros', hue='equipos', data=dataset, palette={'real':'yellow', 'barca': 'red', 'atletico': 'blue'})

它对我有用。

于 2021-05-12T13:32:46.390 回答