Fixing color in scatter plots in matplotlib

前端 未结 2 1250
灰色年华
灰色年华 2020-12-13 14:22

I want to fix the color range on multiple scatter plots and add in a colorbar to each plot (which will be the same in each figure). Essentially, I\'m fixing all aspects of

2条回答
  •  借酒劲吻你
    2020-12-13 15:23

    Setting vmin and vmax should do this.

    Here's an example:

    import matplotlib.pyplot as plt
    
    xyc = range(20)
    
    plt.subplot(121)
    plt.scatter(xyc[:13], xyc[:13], c=xyc[:13], s=35, vmin=0, vmax=20)
    plt.colorbar()
    plt.xlim(0, 20)
    plt.ylim(0, 20)
    
    plt.subplot(122)
    plt.scatter(xyc[8:20], xyc[8:20], c=xyc[8:20], s=35, vmin=0, vmax=20)   
    plt.colorbar()
    plt.xlim(0, 20)
    plt.ylim(0, 20)
    
    plt.show()
    

    And the plot this produces:

提交回复
热议问题