[英]how to plot a map using geopandas and matplotlib
there seems to be an issue with my code.我的代码似乎有问题。 My goal is to plot a map that represents an outcome (population) accross the regions of Benin.
我的目标是 plot 和 map 代表整个贝宁地区的结果(人口)。
import pandas as pd
import matplotlib as mpl
database_path = "datafinalproject.csv"
database = pd.read_csv(database_path)
#Creating a geodataframe
points = gpd.points_from_xy(database["longitude"], database["latitude"], crs="EPSG:4326")
map = gpd.GeoDataFrame (database, geometry=points)
I get this message when I type map.plot
and I when I type map.plot(column='population')
, I get an empty map.当我键入
map.plot
时收到此消息,当我键入map.plot(column='population')
时,我得到一个空的 map。
Can you help me solve this problem?你能帮我解决这个问题吗?
database.head()
gives: database.head()
给出:
map.plot()
will work in a Jupyter notebook but not in a normal Python environment. map.plot()
可以在 Jupyter notebook 中使用,但不能在正常的 Python 环境中使用。
You should import matplotlib.pyplot
and add plt.show()
at the end of your code:您应该导入
matplotlib.pyplot
并在代码末尾添加plt.show()
:
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
database_path = "datafinalproject.csv"
database = pd.read_csv(database_path)
#Creating a geodataframe
points = gpd.points_from_xy(database["longitude"], database["latitude"], crs="EPSG:4326")
map = gpd.GeoDataFrame (database, geometry=points)
map.plot()
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.