我希望在 seaborn stripplot 中將分類變數可視化為標記樣式,但這似乎并不容易。是否有捷徑可尋。例如,我正在嘗試運行此代碼
tips = sns.load_dataset("tips")
sns.stripplot(x="day", y="total_bill", hue="time", style="sex", jitter=True, data=tips)
這失敗了。另一種方法是使用 relplot ,它確實提供了選項,但無法插入jitter,這使得可視化效果不太好。
sns.relplot(x="day", y="total_bill", hue="time", data=tips, style="sex")
提供這個的作品

有沒有辦法使用stripplot/catplot/swarmplot來做到這一點?
編輯:
有了sns.relplot你可以通過所有的次要情節迭代:
g = sns.relplot(x="day", y="total_bill", hue="time", data=tips, style="sex")
for ax in g.axes.flat:
for points in ax.collections:
vertices = points.get_offsets().data
if len(vertices) > 0:
vertices[:, 0] = np.random.uniform(-0.3, 0.3, vertices.shape[0])
points.set_offsets(vertices)
xticks = ax.get_xticks()
ax.set_xlim(xticks[0] - 0.5, xticks[-1] 0.5) # the limits need to be moved to show all the jittered dots
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/354648.html
標籤:Python matplotlib jupyter-笔记本 海生 jupyter
