[英]Scatterplot with labeled data, marker in relation to label
我想用標記數據散點圖數據集。 我希望將幾個類顯示在不同的標記 styles 中。 對於數據生成,我使用以下命令:
from sklearn.datasets import make_moons
X, y = make_moons(n_samples = 100, noise = 0.15)
數據生成后:
X = array([[ 0.83193416, 0.67054039],
[ 1.4017985 , -0.34708943],
...
[ 1.02640652, -0.58107469],
[-1.08443914, 0.51960219]])
y = array([0, 1, 1, 1, 0, ... 1, 0])
已生成相同大小的 Arrays,y 是 X 中數據的 label。標記為 0 的數據應顯示為圓形,標記為 1 的數據應顯示為三角形。 這是它的外觀示例:示例
提前致謝。
使用y
作為選擇器來過濾 X 的行。plot 的 x 和 y 向量在 X 的 * 列中,因此我們必須轉置 plot 的數據才有意義。 飛濺星*
用於將列拆分為前兩個 arguments 用於 plot()。 colors 和形狀在最終參數“bo”和“g^”中:
import matplotlib.pyplot as plt
plt.plot(*X[y==0].T, 'bo') # blue circles (replace o -> s for squares like the picture)
plt.plot(*X[y==1].T, 'g^') # green triangles
plt.axis('equal')
plt.grid('on')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.