1
다음 코드를 입력해야 작동하지 않습니다. 어떤 이유로 든 GeoPandas * .plot()은 작동하지 않지만 일부 간단한 플롯에는 팬더와 지오 판다를 모두 사용하고 싶습니다.모양이 다각형으로 매핑
저는 GeopPandas에서 Shapely 오브젝트를 가져 와서 Basemap에 그려 봅니다. 문제는 폴리곤이 플롯되지 않는다는 것입니다. GeoPandas.geometry에서 반복하여 축 컬렉션에 추가 한 다음 plot()을 사용하여 사용하지 마십시오. Basemap이 잘 작동하는 것처럼 보입니다. 코드는 오류를주지 않지만 폴리곤 카운티는 나타나지 않습니다.
도움을 주셔서 감사합니다!
import geopandas as gpd
from descartes import PolygonPatch
import matplotlib as mpl
import mpl_toolkits.basemap as base
import matplotlib.pyplot as plt
counties_file = r'C:\Users\...\UScounties\UScounties.shp'
counties = gpd.read_file(counties_file)
#new plot
fig = plt.figure(figsize=(5,5),dpi=300)
#ax = fig.add_subplot(111)
ax = ax = plt.gca()
minx, miny, maxx, maxy = counties.total_bounds
#map
m = base.Basemap(llcrnrlon=minx, llcrnrlat=miny,
urcrnrlon=maxx, urcrnrlat=maxy,
resolution='h', area_thresh=100000,
projection='merc')
patches = []
#add polygons
for poly in counties.geometry:
#deal with single polygons and multipolygons
if poly.geom_type == 'Polygon':
p = PolygonPatch(poly, facecolor='blue', alpha=1)
#plt.gca().add_patch(p)
#ax.add_patch(p)
patches.append(p)
elif poly.geom_type == 'MultiPolygon':
for single in poly:
q = PolygonPatch(single,facecolor='red', alpha=1)
#ax.add_patch(p)
patches.append(q)
m.drawcoastlines(linewidth=.1)
m.fillcontinents()
m.drawcountries(linewidth=.25,linestyle='solid')
m.drawstates(linewidth=.25,linestyle='dotted')
m.drawmapboundary(fill_color='white')
ax.add_collection(mpl.collections.PatchCollection(patches, match_original=True))
ax.plot()
plt.show()
무엇이 잘못 되었나요? 문제를 상세히 설명하십시오. –
GeoPandas'plot()'메서드로는 작동하지 않는 것은 무엇입니까? 아직지도 투영을 처리하지 않지만 데이터 좌표계에 플롯이 표시되어야합니다. – Kelsey