使用地gepandas的空间饼图
我正在使用geopandas进行此 -
us_states = gpd.read_file("conus_state.shp")
data = gpd.read_file("data_file.shp")
fig, ax = plt.subplots(figsize= (10,10))
us_states.plot(color = "None", ax = ax)
data.plot(column = ["Column1","Column2"], ax= ax, kind = "pie",subplots=True)
这给我以下错误 -
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\LSRATH~1.STU\AppData\Local\Temp/ipykernel_17992/1047905594.py in <module>
1 fig, ax = plt.subplots(figsize= (10,10))
2 us_states.plot(color = "None", ax = ax)
----> 3 diff_env.plot(column = ["WS_MON1","WS_MON2"], ax= ax, kind = "pie")
c:\python38\lib\site-packages\geopandas\plotting.py in __call__(self, *args, **kwargs)
951 if kind in self._pandas_kinds:
952 # Access pandas plots
--> 953 return PlotAccessor(data)(kind=kind, **kwargs)
954 else:
955 # raise error
c:\python38\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
921 if isinstance(data, ABCDataFrame):
922 if y is None and kwargs.get("subplots") is False:
--> 923 raise ValueError(
924 f"{kind} requires either y column or 'subplots=True'"
925 )
ValueError: pie requires either y column or 'subplots=True'
即使在指定后,subplots = true,它也无法正常工作。
如何使用2列数据框制作饼图?
以下是相关列的前五行 -
diff_env[["Column1", "Column2", "geometry"]].head().to_dict()
{'Column1': {0: 2, 1: 0, 2: 0, 3: 1, 4: 12},
'Column2': {0: 2, 1: 0, 2: 0, 3: 1, 4: 12},
'geometry': {0: <shapely.geometry.point.Point at 0x2c94e07f190>,
1: <shapely.geometry.point.Point at 0x2c94e07f130>,
2: <shapely.geometry.point.Point at 0x2c94e07f0d0>,
3: <shapely.geometry.point.Point at 0x2c94bb86d30>,
4: <shapely.geometry.point.Point at 0x2c94e07f310>}}
I am trying to make a pie chart that looks like the below -
I am using geopandas for that-
us_states = gpd.read_file("conus_state.shp")
data = gpd.read_file("data_file.shp")
fig, ax = plt.subplots(figsize= (10,10))
us_states.plot(color = "None", ax = ax)
data.plot(column = ["Column1","Column2"], ax= ax, kind = "pie",subplots=True)
This gives me the following error-
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\LSRATH~1.STU\AppData\Local\Temp/ipykernel_17992/1047905594.py in <module>
1 fig, ax = plt.subplots(figsize= (10,10))
2 us_states.plot(color = "None", ax = ax)
----> 3 diff_env.plot(column = ["WS_MON1","WS_MON2"], ax= ax, kind = "pie")
c:\python38\lib\site-packages\geopandas\plotting.py in __call__(self, *args, **kwargs)
951 if kind in self._pandas_kinds:
952 # Access pandas plots
--> 953 return PlotAccessor(data)(kind=kind, **kwargs)
954 else:
955 # raise error
c:\python38\lib\site-packages\pandas\plotting\_core.py in __call__(self, *args, **kwargs)
921 if isinstance(data, ABCDataFrame):
922 if y is None and kwargs.get("subplots") is False:
--> 923 raise ValueError(
924 f"{kind} requires either y column or 'subplots=True'"
925 )
ValueError: pie requires either y column or 'subplots=True'
Even after specifying, subplots = True, it does not work.
How can I make a pie chart using 2 columns of the dataframe?
Below are the first five rows of the relevant columns-
diff_env[["Column1", "Column2", "geometry"]].head().to_dict()
{'Column1': {0: 2, 1: 0, 2: 0, 3: 1, 4: 12},
'Column2': {0: 2, 1: 0, 2: 0, 3: 1, 4: 12},
'geometry': {0: <shapely.geometry.point.Point at 0x2c94e07f190>,
1: <shapely.geometry.point.Point at 0x2c94e07f130>,
2: <shapely.geometry.point.Point at 0x2c94e07f0d0>,
3: <shapely.geometry.point.Point at 0x2c94bb86d30>,
4: <shapely.geometry.point.Point at 0x2c94e07f310>}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
样本数据
完整代码
输出
sample data
full code
output