Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn scatterplot markers argument not working

Original Plot

I am trying to plot the following graph with the following code:

from sklearn.datasets import make_blobs
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

X,y = make_blobs(n_samples=21,centers=7,shuffle=False)

palette = sns.color_palette("bright", 7)

fig, ax = plt.subplots(figsize=(4,4))
p1 = sns.scatterplot(X[:,0],X[:,1],palette=palette, hue=y,legend='full')

enter image description here

The plot I failed to achieve

Now, in addition to different colors for different labels, I also want different shapes. However, even when I add the markers argument, nothing changes.

marker_list = ['.', ',', 'o', 'v', '^', '<', '>']

fig, ax = plt.subplots(figsize=(4,4))
p1 = sns.scatterplot(X[:,0],X[:,1],palette=palette, hue=y,legend='full',markers=marker_list)

enter image description here

Why does the marker argument not work?

like image 817
Raven Cheuk Avatar asked Oct 28 '18 15:10

Raven Cheuk


1 Answers

You should add the style grouping variable, as described in the scatterplot doc. The following line should work:

p1 = sns.scatterplot(X[:,0],X[:,1],palette=palette, hue=y, style=y, legend='full',markers=marker_list)
like image 90
rinkert Avatar answered Nov 03 '22 00:11

rinkert