Add a contour condition in a contourf plot

Viewed 30

I have this "nice" plot,

to which I would really like to add two contours.

To make (very) long story short, in the MWE plot you can see the trends of a certain variable of my netCDF - here attached - and the p-values, with markers, under the chosen threshold. The two contours I would like to add are related to the values of another netCDF input variable, "blocking_ANNI". If, for the same lat lon grid point,

0 < blocking_ANNI[i,j] =< 10 a contour. Another one (different color) for 10 < blocking_ANNI[i,j] < 20.

In my perfect idea, for continuous points I'd love to see a unique line, like in plot.contour; otherwise (for not continuous points), circles of the same color eventually surrounding the significance markers.

Any help would be greatly appreciated!

MWE

import numpy as np 
import xarray as xr
import netCDF4
import matplotlib.pyplot as plt
import cartopy.crs as ccrs

input_path = 'your_path_of_choice'
input_file_trends = 'blocking_trends_filtered.nc'
trends = xr.open_dataset(input_path + input_file_trends)

fig = plt.figure()
ax1 = fig.add_subplot(111, projection=ccrs.NorthPolarStereo())

mappa1 = ax1.contourf(
                    trends['count_pendenza']['lon'], 
                    trends['count_pendenza']['lat'], 
                    (trends['count_pendenza']*10),
                    #ax=ax1, 
                    levels=np.arange(-0.30, 0.30, 0.02),
                    extend = 'both', 
                    transform=ccrs.PlateCarree(),
                    cmap='Spectral_r',  
                    )
cb2 = fig.colorbar(
                mappa1, 
                label= 'events/decade', 
                shrink = 0.5,
                )

lat_size = len(trends['count_pvalue']['lat'])
lon_size = len(trends['count_pvalue']['lon'])

#Significance
for i in range(lat_size):
    for j in range(lon_size):
        if (trends['count_pvalue'][i,j] <= 0.1):
            ax1.plot(
                trends['count_pvalue'][i,j]['lon'], 
                trends['count_pvalue'][i,j]['lat'],  
                color = 'black',
                marker='2',
                markersize= 0.2, 
                transform=ccrs.PlateCarree()
                )

ax1.coastlines()
plt.show()
0 Answers
Related