본문 바로가기

Python Tips7

matplotlib.pyplot 팁: legend box 밖에, 한글 입력 plt.legend(loc='center left', bbox_to_anchor=(1, 0.5)) 참조: https://stackoverflow.com/questions/4700614/how-to-put-the-legend-out-of-the-plot 한글입력: plt.rcParams["font.family"] = 'nanumgothic' plt.rcParams['axes.unicode_minus'] = False 이거 추가해주면됨. 나눔고딕없으면 다른 폰트로 ㄱ 2020. 6. 15.
CountVectorizer + pyLDAvis (N-gram LDA) dictionary = gensim.corpora.Dictionary() dictionary.token2id = dict((word, uid) for word, uid in vect.vocabulary_.items()) pyLDAvis를 써서 위와 같이 시각화를 하고싶은데 bigram같은 feature를 뽑고싶은경우가 있을 것이다. sklearn의 CountVectorizer를 쓰면 가능하지만, 이것을 gensim의 라이브러리를 써서 pyLDAvis로 어떻게 변환하는지에 대한 글이 없길래 써본다. 우선 아래의 라이브러리를 import한다. from sklearn.feature_extraction.text import CountVectorizer from gensim.models import LdaMode.. 2020. 6. 10.
Python MapBox 지도 visualize import pydeck def viz(mdf): # 2014 locations of car accidents in the UK UK_ACCIDENTS_DATA = ('https://raw.githubusercontent.com/uber-common/' 'deck.gl-data/master/examples/3d-heatmap/heatmap-data.csv') layer = pydeck.Layer( 'ScatterplotLayer', mdf, get_position='[x, y]', auto_highlight=True, elevation_scale=50, pickable=True, elevation_range=[0, 1], extruded=True, get_radius=10, get_fill_color=[.. 2020. 5. 11.
주로 쓰는 좌표계 정리 http://www.localdata.kr/ 여기서 x,y가 쓰는 좌표: TM좌표계 +proj=tmerc +lat_0=38 +lon_0=127.0028902777778 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43 UTM-K (EPSG:5178) +proj=tmerc +lat_0=38 +lon_0=127.5 +k=0.9996 +x_0=1000000 +y_0=2000000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43 KATEC 카텍좌표계 +pro.. 2020. 4. 8.
Proj Transformer 좌표 변환 from pyproj import Proj, transform inProj = Proj('+proj=tmerc +lat_0=38 +lon_0=127.0028902777778 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +units=m +no_defs +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43') outProj = Proj(init='epsg:4326') x1,y1 = yldf.iloc[0].x, yldf.iloc[0].y x2,y2 = transform(inProj,outProj,x1,y1) print (y2,',',x2) 간단하게는 이렇게 바꾸거나 from pyproj import Transformer transform.. 2020. 4. 8.
GeoPandas 에서 GeoWithin Query하기 우리가 원하는 범위의 Polygon이 아래와 같은 형태라고 하자. yunnam_large = {'type': 'Polygon', 'coordinates': [[[126.92572992898702, 37.55835818322421], [126.92616538295539, 37.55864227038824], [126.92658623986753, 37.55938810776263], [126.92677406036564, 37.56118120785994], [126.9282886257802, 37.56334452890169], [126.92638553613328, 37.56494713073428], [126.9243245551222, 37.565900883346934], [126.9196036221869, 37... 2020. 3. 17.
dictionary 값으로 정렬하기 for w in sorted(d, key=d.get, reverse=True): print(w, d[w]) 2020. 3. 17.