본문 바로가기

반응형

Programing Language/Python

(32)
[visualization]netCDF 관련 지구 시각화 NetCDF netCDF는 3차원 혹은 4차원 데이터, 특히 위성 등으로 측정된 지구, 국가단위의 map data를 구성하는 형태이다. 비교적 자세한 정보들을 담고있어, 그 자체에서 필요한 정보들을 다 담고있다. 최신은 netCDF4이며, python의 경우 netCDF3와 netCDF4의 경우 읽어오는 패키지가 다를 수도 있다. 보통 netCDF4 패키지로 읽어온다. Data Import 아래의 데이터는 NASA의 위성데이터중 하나인 CCAR 데이터이다. 시공간마다의 각 cite에서 해수표면 높이를 담고있다. 읽어온 f_nc를 실행하면 데이터에 대한 description이 나온다. 이 데이터의 경우 가장 아래에 제일 중요한 data의 dimension에 대한 정보가 담겨져 있다. from netCDF4..
[plot]LineCollection: edges(끈킨 선 여러개)를 빨리 그릴 때!? 원래 코드 (겁나 느림 주의) # xs = [[fn1, tn1], [fn2, tn2]...] # ys = [[fn1, tn1], [fn2, tn2]...] plt.plot(xs.T, ys.T, lw = 1, c = 'r') plt.show() 개선된 코드: 빠르다!!! fn = np.array(list(zip(fx,fy))) tn = np.array(list(zip(tx,ty))) ptrs = np.array(list(zip(fn,tn))) ln_coll = matplotlib.collections.LineCollection(ptrs, lw = lw*.05, colors='r') fig, ax = plt.subplots() ax.add_collection(ln_coll) ax..
[plot]matplotlib arrow arrow_params = {'length_includes_head': True, 'shape': 'right'}#, # 'head_starts_at_zero': True} plt.arrow(x, y, dx, dy, alpha = .3, label = lb_road[rr], overhang = .2, ec = None, color = None, fc = cmap[rr%100], linewidth=0, width = .0003, head_width=.001, head_length=.001, **arrow_params) figure는 figsize=(20,20) 기반으로 했을 때 width, head_width, head_length가 저정도가 적절하..
[plot]gridspec: subplots 업그레이드 버전 Introduction Figure를 그릴 때, subplot만으로는 뭔가 아쉬울 때, 영역을 내마음대로 나누고 싶을 때, 그럴때 필요한게 바로 gridspec Features Figure를 그릴 때 영역을 내 자유자재로 나눌 수 있음 Usage import matplotlib.gridspec as gridspec # define gridspec spec = gridspec.GridSpec(ncols=3, nrows=5, figure=fig) # draw specific grid ax = fig.add_subplot(spec[i//3,i%3]) ax = fig.add_subplot(spec[i:i+1,i:i+2]) Example code import matplotlib.pyplot as plt impor..

반응형