6Pi*_*eer 3 matplotlib python-3.x pandas spyder geopandas
我正在尝试在 geopandas 地图上的 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
Run Code Online (Sandbox Code Playgroud)
[
我自己得到了正确的答案,这是我的结果:
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")
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3018 次 |
| 最近记录: |