代码之家  ›  专栏  ›  技术社区  ›  Soerendip

如何删除matplotlib散点图的正方形标记中的圆边?

  •  0
  • Soerendip  · 技术社区  · 6 年前

    我正在用matplotlib生成一个使用非常小的标记大小的散点图。我用过

    figure(figsize=(3,2),dpi=1000)
    i = np.arange(1,100)
    x = i * 3.1426 / np.max(i)
    y = np.sin(x)
    s = 1/i
    print(s)
    scatter(x/10,y, marker='s', s=s)
    

    enter image description here 如果你仔细观察,你会发现标记实际上从来没有真正的正方形,而是有圆形的边缘。所以,如果你使用小的标记大小,标记实际上会变成圆形。是故意的吗?我的问题是:我怎样才能去掉圆边,并使标记真正平方的所有大小?

    1 回复  |  直到 6 年前
        1
  •  1
  •   harvpan    6 年前

    您需要使用 edgecolors='none'

    plt.scatter(x/10,y, marker='s', s=s, edgecolors='none')
    

    给予:

    enter image description here

    注意:您可能需要再次设置大小,因为没有边缘颜色,标记会变薄。