why does pcolor with masked array still fill quadrangles connecting to masked points, and how do I stop this?

前端 未结 1 561
刺人心
刺人心 2020-12-22 01:19

To mitigate the problem described here, I\'m trying to draw my pcolor plot in two complimentary parts. I have X and Y data that corre

相关标签:
1条回答
  • 2020-12-22 02:21

    I see maybe I wasn't clear enough on my quick comment on the other question, but by masking I mean that the grid needs to by masked, not the values.

    from numpy import array, ma
    import matplotlib.pyplot as plt
    
    lons = array([[ 100.,  120.,  140.,  160.,  180.],
           [ 120.,  140.,  160.,  180., -160.],
           [ 140.,  160.,  180., -160., -140.],
           [ 160.,  180., -160., -140., -120.],
           [ 180., -160., -140., -120., -100.],
           [-160., -140., -120., -100.,  -80.]])
    
    lats = array([[  0.,  10.,  20.,  30.,  40.],
           [  0.,  10.,  20.,  30.,  40.],
           [  0.,  10.,  20.,  30.,  40.],
           [  0.,  10.,  20.,  30.,  40.],
           [  0.,  10.,  20.,  30.,  40.],
           [  0.,  10.,  20.,  30.,  40.]])
    
    bts = array([[ 0,  1,  2,  3,  4],
           [ 5,  6,  7,  8,  9],
           [10, 11, 12, 13, 14],
           [15, 16, 17, 18, 19],
           [20, 21, 22, 23, 24],
           [25, 26, 27, 28, 29]])
    
    fig, (ax,ax2) = plt.subplots(ncols=2)
    ax.pcolor(ma.masked_where(lons>0, lons), 
           ma.masked_where(lons>0, lats), 
           ma.masked_where(lons>0, bts))
    
    ax2.pcolor(ma.masked_where(lons<0, lons), 
           ma.masked_where(lons<0, lats), 
           ma.masked_where(lons<0, bts))
    
    plt.show()
    

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