OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

pyplot.contour() with specific levels returns incomplete figure

  • Thread starter Thread starter Jerry
  • Start date Start date
J

Jerry

Guest
I'm trying to plot a figure of composite of extreme warming cases from CESM2 large ensemble climate data. I tried the following codes and it returned an incomplete world map.

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

plt.figure(figsize=(12,10))
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=0))
level = [-60,-50,-40,-30,-20,-10,10,20,30,40,50,60] 
ax.contour(lon, lat, z3_composite_mean - z3_djf_mean, levels=level,colors='k',transform=ccrs.PlateCarree())

enter image description here


But the codes below gave complete map!

Code:
level = np.arange(-60,60.1,10)  
ax.contour(lon, lat, z3_composite_mean - z3_djf_mean, levels=level, colors='k',transform=ccrs.PlateCarree())

enter image description here


Or is it related to plotting coastlines with cartopy packages?

Code:
ax.add_feature(cartopy.feature.COASTLINE) 
ax.add_feature(cartopy.feature.LAND, color='lightgrey')

Hope to figure out this confusing result, thanks!

I tried the contourf function, and the shading looks normal. Only contour plot suffers problem :(
<p>I'm trying to plot a figure of composite of extreme warming cases from CESM2 large ensemble climate data. I tried the following codes and it returned an incomplete world map.</p>
<pre><code>import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy

plt.figure(figsize=(12,10))
ax = plt.axes(projection=ccrs.PlateCarree(central_longitude=0))
level = [-60,-50,-40,-30,-20,-10,10,20,30,40,50,60]
ax.contour(lon, lat, z3_composite_mean - z3_djf_mean, levels=level,colors='k',transform=ccrs.PlateCarree())
</code></pre>
<p><img src="https://i.sstatic.net/82c1nm9T.png" alt="enter image description here" /></p>
<p>But the codes below gave complete map!</p>
<pre><code>level = np.arange(-60,60.1,10)
ax.contour(lon, lat, z3_composite_mean - z3_djf_mean, levels=level, colors='k',transform=ccrs.PlateCarree())
</code></pre>
<p><img src="https://i.sstatic.net/nSiZXU7P.png" alt="enter image description here" /></p>
<p>Or is it related to plotting coastlines with cartopy packages?</p>
<pre><code>ax.add_feature(cartopy.feature.COASTLINE)
ax.add_feature(cartopy.feature.LAND, color='lightgrey')
</code></pre>
<p>Hope to figure out this confusing result, thanks!</p>
<p>I tried the contourf function, and the shading looks normal. Only contour plot suffers problem :(</p>
 

Latest posts

Top