每个X的多个Y值的散点图为每个X值着色

时间:2020-10-26 20:29:58

标签: python-3.x matplotlib

我要为每个公司名称分配一种颜色。我试过在散点图中使用color参数,但是在公司名称中使用了不同的颜色。

import matplotlib.pyplot as plt
import seaborn as sns
y = [[0.15,0.25,0.63],[0.69,0.24,0.85],[0.85,0.41,0.73]]
x = [1,2,3]
sns.set_style("dark")
plt.title("Company Records")
for xe, ye in zip(x, y):
    plt.scatter([xe] * len(ye), ye)
plt.xticks([1,2,3]);
plt.axes().set_xticklabels(['ACTP', 'ATC',"LKO"],rotation = 45);

1 个答案:

答案 0 :(得分:1)

将自定义颜色与zip一起传递:

colors = ['red', 'magenta', 'pink']
for xe, ye,c in zip(x, y,colors):
    plt.scatter([xe] * len(ye), ye, c=c)
plt.xticks([1,2,3]);
plt.axes().set_xticklabels(['ACTP', 'ATC',"LKO"],rotation = 45);

输出:

enter image description here

相关问题