![](/img/trans.png)
[英]How do you display the scale in meters, the north arrow and the axes in latitude and longitude on a map with Geopandas?
[英]how to add a "North Arrow" on a geopandas map
我使用 geopandas 创建了一个 map,但我无法在 map 上添加“指北针”。
创建 map 后,我尝试使用 matplotlib.image 模块添加“指北针”,并尝试了不同的方法(请参见下面的示例),但都没有提供好的结果。 我正在寻找更好的代码,可以在地图上添加一个好的“指北针”
import matplotlib.image as img
from matplotlib.offsetbox import TextArea, DrawingArea, OffsetImage,
AnnotationBbox
im=img.imread(r'C:\Users\jnisengw\Dropbox\2019\Data
Science\QGIS\north_arrow1.png')
imagebox = OffsetImage(im,zoom=0.27)
ab = AnnotationBbox(imagebox, (598500,4699000))
ax.add_artist(ab)
如果只需要添加一个简单的箭头,还可以考虑annotate()
方法。
import geopandas as gpd
import matplotlib.pyplot as plt
gdf = gpd.read_file(gpd.datasets.get_path('nybb'))
fig, ax = plt.subplots(figsize=(6, 6))
gdf.plot(ax=ax)
x, y, arrow_length = 0.5, 0.5, 0.1
ax.annotate('N', xy=(x, y), xytext=(x, y-arrow_length),
arrowprops=dict(facecolor='black', width=5, headwidth=15),
ha='center', va='center', fontsize=20,
xycoords=ax.transAxes)
注意:当您通过xycoords=ax.transAxes
时,x,y 坐标被归一化, x, y = 0.5, 0.5
表示您将箭头放在 map 的中间。
万一有人还需要这个...
EOmaps v3.1现在有一个正确的指北针并且可以与 geopandas 很好地交互!
from eomaps import Maps
m = Maps()
m.add_feature.preset.ocean()
m.add_compass(style="north arrow")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.