【问题标题】:How do I apply a line between two points in geopanda e.g. between 2 cities如何在 geopanda 中的两点之间应用一条线,例如2个城市之间
【发布时间】:2020-12-22 14:36:00
【问题描述】:

我正在尝试在我的 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
    

[

【问题讨论】:

    标签: python-3.x pandas matplotlib spyder geopandas


    【解决方案1】:

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

    
    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")
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-25
      • 2020-02-16
      • 1970-01-01
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多