gpt4 book ai didi

python-3.x - 如何在 geopanda 中的两点之间应用一条线,例如2个城市之间

转载 作者:行者123 更新时间:2023-12-05 02:05:14 27 4
gpt4 key购买 nike

我正在尝试在 geopandas map 上的 2 个城市之间绘制一条绿线结果应显示带有红点的 2 个城市和城市名称以及两个城市之间的绿线

希望你能帮帮我!提前致谢!

我试了几次,但我没有得到画线的关键

import geopandas as gpd
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


###################### The Map of Germany is plotted here

plt.style.use('seaborn')
plz_shape_df = gpd.read_file(r'C:\Users\XXXXX\geopanda\plz-gebiete.shp', dtype={'plz': str})
plz_shape_df.head()
plt.rcParams['figure.figsize'] = [16, 11]
fig, ax = plt.subplots()
plz_shape_df.plot(ax=ax, color='orange', alpha=0.8)

ax.set(
title='Germany',
aspect=1.3,
facecolor='lightblue');

################ The dict: new_dict3 with the 2 cities gets plotted

new_dict3 = {
'Stuttgart': (9.181332, 48.777128),
'Munich': (11.576124, 48.137154),
}

for c in new_dict3.keys():
ax.text(
x=new_dict3[c][0],
y=float(new_dict3[c][1]) + 0.1,
s=c,
fontsize = 12,
ha = "center",
)

ax.plot(
new_dict3[c][0],
new_dict3[c][1],
marker = "o",
c = "red",
alpha = 2.0
)

############### Now I want to plot a green line between the 2 cities of the new_dict3

ax.plot(
x= new_dict3[c][0],
y= float(new_dict3[c][1]) + 0.1,
linestyle = "--",
c = "green",
marker="",
)

#this doesn't work

[ the result of plotting the map before trying to plot the line

最佳答案

我自己得到了正确的答案,这是我的结果:


Stuttgart = [9.181332, 48.777128]
Munich = [11.576124, 48.137154]

x_values = [ Stuttgart[0], Munich[0]]
y_values = [ Stuttgart[1], Munich[1]]

plt.plot(x_values, y_values, linewidth = 5, linestyle = "--", color = "green")

关于python-3.x - 如何在 geopanda 中的两点之间应用一条线,例如2个城市之间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63722226/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com