首页 > 解决方案 > 循环内带有空圆圈的散点图

问题描述

我正在寻找一种简单而优雅的方法来制作具有多个数组的散点图,使用空圆圈作为标记颜色应该自动选择。例如,我可以很容易地制作一个带有实心圆的图:

a = {'1': np.random.rand(10), '2': np.random.rand(10), '3': np.random.rand(10)}
fig,ax = plt.subplots()
for y in ['2', '3']:
    ax.scatter(a[y], a['1'], label=y)

如果我想使用 kwargs facecolor="none",标记就会消失。不知何故我需要自动分配颜色edgecolor

标签: pythonmatplotlibplotscatter-plot

解决方案


C0通过遵循默认调色板的、C1等手动分配边缘颜色:

a = {'1': np.random.rand(10), '2': np.random.rand(10), '3': np.random.rand(10)}
fig,ax = plt.subplots()
for i, y in enumerate(['2', '3']):
    ax.scatter(a[y], a['1'], label=y, facecolor='none', edgecolor=f'C{i}')

推荐阅读