matplotlib tricks(一)—— 多类别数据的 scatter(cmap)

来源:互联网 发布:华为云计算认证培训 编辑:程序博客网 时间:2024/06/06 08:49

cmap 的选择:

  • binary
  • seismic
  • Reds

多类别数据的 scatter(逐点散列),在 matplotlib 中的实现关键在于,color关键字的定义:

def plot_scatter(values, cls):    # Create a color-map with a different color for each class.    import matplotlib.cm as cm    cmap = cm.rainbow(np.linspace(0.0, 1.0, num_classes))    # Get the color for each sample.    colors = cmap[cls]    # Extract the x- and y-values.    x = values[:, 0]    y = values[:, 1]    # Plot it.    plt.scatter(x, y, color=colors)    plt.show()
0 0