Rav*_*euk 5 matplotlib python-3.x seaborn
我正在尝试使用以下代码绘制下图:
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')
Run Code Online (Sandbox Code Playgroud)
现在,除了不同标签的不同颜色外,我还想要不同的形状。但是,即使我添加了markers参数,也没有任何改变。
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)
Run Code Online (Sandbox Code Playgroud)
为什么marker论证不起作用?
您应该添加style分组变量,如散点图文档中所述。以下行应该有效:
p1 = sns.scatterplot(X[:,0],X[:,1],palette=palette, hue=y, style=y, legend='full',markers=marker_list)
Run Code Online (Sandbox Code Playgroud)