Mine
Mine

Reputation: 861

Scatter Plot of Multiple Y Values for each X coloring each X value

For each company name I want to assign a color. I tried playing with color parameter in scatterplot but that gives different colors within company names.

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);

Upvotes: 1

Views: 699

Answers (1)

Quang Hoang
Quang Hoang

Reputation: 150785

Pass the custom colors along with 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);

Output:

enter image description here

Upvotes: 1

Related Questions