Zero-value colour in matplotlib hexbin

后端 未结 1 999
猫巷女王i
猫巷女王i 2021-02-19 14:59

I have some spatially-distributed data. I\'m plotting this with matplotlib.pyplot.hexbin and would like to change the \"background\" (i.e. zero-value) colour. An ex

相关标签:
1条回答
  • 2021-02-19 15:14

    hexbin(x,y,mincnt=1) should do the trick. Essentially, you only want to display the hexagons with more than 1 count in them.

    from numpy import linspace
    from numpy.random import normal
    from pylab import hexbin,show
    
    n = 2**6
    
    x = linspace(-1,1,n)
    y = normal(0,1,n)
    
    h = hexbin(x,y,gridsize=10,mincnt=0)
    

    gives, Bins with zero counts included

    and h = hexbin(x,y,gridsize=10,mincnt=1) gives, Bin count starts at one

    0 讨论(0)
提交回复
热议问题