Reputation: 115
I have the following code:
from matplotlib import pyplot as plt
import seaborn as sns
fig = plt.figure()
fig.suptitle('Average GPA and Standard Deviation per course combination', fontsize=15)
plt.xlabel('Standard Deviation of Average GPA', fontsize=12)
plt.ylabel('Average GPA', fontsize=12)
colors = ['#E74C3C', '#76448A', '#3498DB', '#17A589', '#F1C40F', '#F39C12', '#CA6F1E', '#B3B6B7', '#34495E',
'#F5B7B1']
marker = ['.','v','^','1','2','8','p','P','x','X']
g = sns.scatterplot(x=all_stdev, y=all_gpas, hue=final_courses)
g.legend(loc='center left', bbox_to_anchor=(1, 0.5), ncol=1)
plt.show()
the all_stdev, all_gpas, final_courses are lists and change everytime based on the user, since these are recommendations for the user based on input. The result I get is the following for a particular student:
I tried putting markers in order for them to be more easy to understand from the user(the results) but no matter the things I tried I did not manage to do it. The markers would appear in the graph with same color and the legend would still have all colors as shown above. I need to add the markers to the graph and legend as well. Is there a way to do it? I have a list with markers that I would like to use in the code provided.
Upvotes: 1
Views: 790
Reputation: 80329
You need to add the markers and the colors as a parameter to the scatterplot. There still is another problem with the markers. Seaborn complains: Filled and line art markers cannot be mixed. So you need to select either filled or line art markers.
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
fig = plt.figure()
fig.suptitle('Average GPA and Standard Deviation per course combination', fontsize=15)
plt.xlabel('Standard Deviation of Average GPA', fontsize=12)
plt.ylabel('Average GPA', fontsize=12)
colors = ['#E74C3C', '#76448A', '#3498DB', '#17A589', '#F1C40F', '#F39C12', '#CA6F1E', '#B3B6B7', '#34495E', '#F5B7B1']
# marker = ['.', 'v', '^', '1', '2', '8', 'p', 'P', 'x', 'X']
marker = ['o', 'v', '^', '8', '*', 'P', 'D', 'X', 's', 'p']
N = 30
final_courses = np.random.randint(1,11, N) * 10
all_stdev = np.random.uniform(0, 2, N)
all_gpas = np.random.uniform(3, 4, N)
g = sns.scatterplot(x=all_stdev, y=all_gpas, hue=final_courses, style=final_courses, palette=colors, markers=marker)
g.legend(loc='center left', bbox_to_anchor=(1, 0.5), ncol=1)
plt.show()
Upvotes: 2