Python-지구과학-대기과학-가시화그림 시리즈(一)-xarray를 이용하여netCDF 파일을 읽고 그림을 그리기(코드+예시)
1 import numpy as np
2 import xarray as xr
3 import cartopy.crs as ccrs
4 import cartopy.feature as cfeat
5 from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
6 import matplotlib.pyplot as plt
7
8
9 ds = xr.open_dataset('2039071310.003.nc')
10 t = ds['value']
11 lons = ds.lon.data
12 lats = ds.lat.data
13 temp = xr.DataArray(t.data.T, coords=[lats,lons], dims=['latitude','longitude'])
14
15 #
16 proj = ccrs.PlateCarree() #
17 fig = plt.figure(figsize=(16,9)) #
18 ax = fig.subplots(1, 1, subplot_kw={'projection': proj}) #
19 # : 、 、 、
20 ax.add_feature(cfeat.BORDERS.with_scale('50m'), linewidth=0.8, zorder=1)
21 ax.add_feature(cfeat.COASTLINE.with_scale('50m'), linewidth=0.6, zorder=1)
22 ax.add_feature(cfeat.RIVERS.with_scale('50m'), zorder=1)
23 ax.add_feature(cfeat.LAKES.with_scale('50m'), zorder=1)
24 #
25 gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
26 linewidth=1.2, color='k', alpha=0.5, linestyle='--')
27 gl.xlabels_top = False #
28 gl.ylabels_right = False #
29 gl.xformatter = LONGITUDE_FORMATTER #x
30 gl.yformatter = LATITUDE_FORMATTER #y
31 # colorbar
32 cbar_kwargs = {
33 'orientation': 'horizontal',
34 'label': 'Potential',
35 'shrink': 0.8,
36 }
37 #
38 levels = np.arange(0,1,0.1)
39 temp.plot.contourf(ax=ax, levels=levels, cmap='Spectral_r',
40 cbar_kwargs=cbar_kwargs, transform=ccrs.PlateCarree())
41 plt.savefig('test.jpg')
예제 효과(강대류 확률 예보 결과):
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.