jupyter notebook绘制陕西省安康市与汉中市的地图代码
时间: 2023-10-02 12:04:12 浏览: 48
你可以使用python中的geopandas和matplotlib库来绘制地图。以下是一个简单的示例代码,展示如何绘制陕西省安康市和汉中市的地图。
首先,你需要安装geopandas和matplotlib库。可以使用以下命令在终端或Anaconda Prompt中安装:
```
pip install geopandas
pip install matplotlib
```
安装完后,你可以使用以下代码绘制地图:
```python
import geopandas as gpd
import matplotlib.pyplot as plt
# 读取陕西省的地图数据
shaanxi = gpd.read_file('path/to/shaanxi.shp')
# 只保留安康市和汉中市的数据
cities = shaanxi[shaanxi['NAME'].isin(['安康市', '汉中市'])]
# 绘制地图
ax = cities.plot(figsize=(10, 10), edgecolor='white', facecolor='lightgray')
# 添加城市名称标注
for idx, row in cities.iterrows():
ax.annotate(s=row['NAME'], xy=row['geometry'].centroid.coords[0],color='black', fontsize=12)
# 显示地图
plt.show()
```
在上面的代码中,你需要将`path/to/shaanxi.shp`替换为实际的地图数据文件路径。你可以在网上搜索到陕西省的地图数据文件。
运行代码后,你应该会得到一个类似下图的地图:
![陕西省安康市和汉中市地图](https://i.ibb.co/VJjK9Pc/map.png)