sns.scatter 图 python,指定大小
sns.scatter plot python, specify size
我在下面的 sns.scatterplot 中将大小设置为间隙。出现的 Gap 值是 0、0.8、0.16 和 0.24,但是我的数据框中的值是 0、0.5、1 和 2。如何将它们设置为等于我的数据框中的值?
ax = sns.scatterplot(x='Number tapes', y='Ic', hue="Angle of twist (degree)", size="Gap", data=Ic_layers)
图例中显示的值似乎与您所说的数据范围在您的数据框中不一致,但无论如何...
您可以在对 scatterplot()
的调用中使用 legend='full'
来强制 seaborn 为您的 hues/sizes 变量的每个级别显示一个图例项。
N=50
df = pd.DataFrame({'x': np.random.random(size=(N,)), 'y': np.random.random(size=(N,)),
'size': np.random.choice([0, 0.5, 1, 2], size=(N,))})
fig, (ax1, ax2) = plt.subplots(1,2)
sns.scatterplot(x="x", y="y", size="size", data=df, ax=ax1)
ax1.set_title('legend="brief" (default)')
sns.scatterplot(x="x", y="y", size="size", data=df, legend='full', ax=ax2)
ax2.set_title('legend="full"')
我在下面的 sns.scatterplot 中将大小设置为间隙。出现的 Gap 值是 0、0.8、0.16 和 0.24,但是我的数据框中的值是 0、0.5、1 和 2。如何将它们设置为等于我的数据框中的值?
ax = sns.scatterplot(x='Number tapes', y='Ic', hue="Angle of twist (degree)", size="Gap", data=Ic_layers)
图例中显示的值似乎与您所说的数据范围在您的数据框中不一致,但无论如何...
您可以在对 scatterplot()
的调用中使用 legend='full'
来强制 seaborn 为您的 hues/sizes 变量的每个级别显示一个图例项。
N=50
df = pd.DataFrame({'x': np.random.random(size=(N,)), 'y': np.random.random(size=(N,)),
'size': np.random.choice([0, 0.5, 1, 2], size=(N,))})
fig, (ax1, ax2) = plt.subplots(1,2)
sns.scatterplot(x="x", y="y", size="size", data=df, ax=ax1)
ax1.set_title('legend="brief" (default)')
sns.scatterplot(x="x", y="y", size="size", data=df, legend='full', ax=ax2)
ax2.set_title('legend="full"')