How to color `matplotlib` scatterplot using a continuous value [`seaborn` color palettes?]

后端 未结 2 1546
有刺的猬
有刺的猬 2021-02-19 02:05

I have a scatterplot and I want to color it based on another value (naively assigned to np.random.random() in this case).

Is there a way to use

2条回答
  •  無奈伤痛
    2021-02-19 02:22

    import numpy as np
    import seaborn as sns
    import matplotlib.pyplot as plt
    
    x, y, z = np.random.rand(3, 100)
    cmap = sns.cubehelix_palette(as_cmap=True)
    
    f, ax = plt.subplots()
    points = ax.scatter(x, y, c=z, s=50, cmap=cmap)
    f.colorbar(points)
    

提交回复
热议问题