Significance stippling

1,620 views
Skip to first unread message

Damien Irving

unread,
Dec 11, 2014, 2:54:18 PM12/11/14
to scitoo...@googlegroups.com
A common task for weather and climate scientists is to apply stippling or hatching over a plot to indicate regions of statistical significance. At the moment iris doesn't have any convenience functions for this task, so I end up literally iterating though every single grid point and plotting a marker if some threshold is met.

I'm not sure what the answer/solution would be, but I'm wondering if a function could be added to iris to make this task easier? NCL produces very nice stippling and hatching (e.g. https://www.ncl.ucar.edu/Applications/Scripts/conOncon_4.ncl), so this is certainly possible in other languages.



Damien Irving

unread,
Dec 11, 2014, 10:29:37 PM12/11/14
to scitoo...@googlegroups.com
Nevermind... I found the hatch option for contourf which makes stippling really easy.

LeonH

unread,
Dec 17, 2014, 8:44:10 AM12/17/14
to scitoo...@googlegroups.com
I found that hatch with contourf only works for certain file formats and can disappear when you put it in a pdf. This was a matplotlib bug that may have been fixed?

This code does the job for all file formats I have tested:
def stipple(pCube, thresh=0.05, central_long=0):
    """
    Stipple points using plt.scatter for values below thresh in pCube.
    If you have used a central_longitude in the projection, other than 0,
    this must be specified with the central_long keyword
    """
    xOrg = pCube.coord('longitude').points
    yOrg = pCube.coord('latitude').points
    nlon = len(xOrg)
    nlat = len(yOrg)
    xData = np.reshape( np.tile(xOrg, nlat), pCube.shape )
    yData = np.reshape( np.repeat(yOrg, nlon), pCube.shape )
    sigPoints = pCube.data < thresh
    xPoints = xData[sigPoints] - central_long
    yPoints = yData[sigPoints]
    plt.scatter(xPoints,yPoints,s=1, c='k', marker='.', alpha=0.5)

Aleš Kuchař

unread,
Jan 27, 2015, 10:01:36 AM1/27/15
to scitoo...@googlegroups.com
It seems to be still bug in matplotlib. See this link.

Dne středa 17. prosince 2014 14:44:10 UTC+1 LeonH napsal(a):

Rob Chadwick

unread,
Oct 31, 2016, 1:15:51 PM10/31/16
to Iris
I know this is an old thread, but I've just had the same problem and found Leon's code below very useful. One tip is to also include the following line in the stipple function, otherwise it can mess up the underlying contour plot a bit:

    plt.gca().autoscale(False) # To avoid that the scatter changes limits
Reply all
Reply to author
Forward
0 new messages