【问题标题】:plotting a bearing using python on matplotlib using X and Y使用 X 和 Y 在 matplotlib 上使用 python 绘制方位
【发布时间】:2021-05-11 14:37:58
【问题描述】:
  • 我在地图上使用 X, Y matplotlib 使用子图有 3 个已知位置,我需要绘制其中一个塔的方位并在地图上放置一条线。
  • 我目前使用 X、Y 作为开始位置,使用箭头/线作为结束位置。但想知道如何用轴承代替线尾代替x,y。我目前正在研究 Vectors,但没有运气。

我的代码低于任何帮助都会很棒

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math


df = pd.read_csv("Book1.csv")
df.head()
tower1x = [51.69557]
tower1y = [-3.34197]
tower2x = [51.69673]
tower2y = [-3.34235]

tower3x = [51.69630]
tower3y = [-3.34090]


BBox = (df.longitude.min(), df.longitude.max(),
        df.latitude.min(), df.latitude.max())
print (BBox)
     
ruh_m = plt.imread('map.png')

fig, ax = plt.subplots(figsize = (12,12))



ax.scatter(tower1x, tower1y, zorder=1, alpha= 0.5, c='red', s=50, label="Tower 1")
ax.scatter(tower2x, tower2y, zorder=1, alpha= 0.5, c='blue', s=50, label="Tower 2")
ax.scatter(tower3x, tower3y, zorder=1, alpha= 0.5, c='green', s=50, label="Tower 3")

ax.annotate("",xy=(51.69557,-3.34197), xytext=**(51.69799, -3.34155)**, textcoords='data',
            arrowprops=dict(arrowstyle="<-", connectionstyle="arc3"),) # point from tower 1 using X,Y

ax.set_title('Plotting Towers in Aberfan')
ax.set_xlim(BBox[0],BBox[1])
ax.set_ylim(BBox[2],BBox[3])
ax.imshow(ruh_m, zorder=0, extent = BBox, aspect= 'equal')


plt.legend()
plt.show()

【问题讨论】:

标签: python python-3.x pandas matplotlib vector


【解决方案1】:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import math


df = pd.read_csv("Grids.csv")
df.head()
##
###X and Y Coordinates using www.openstreetmap.org
BBox = (df.longitude.min(), df.longitude.max(),
        df.latitude.min(), df.latitude.max())


#Signal power
s1 = int(input("Enter power from tower 1: "))
s2 = int(input("Enter power from tower 2: "))
s3 = int(input("Enter power from tower 3: "))

#weight of signal
w1 = [s1 / ( s1 + s2 +  s3 )]
w2 = [s2 / ( s1 + s2  + s3 )] 
w3 = [s3 / ( s1 + s2 + s3 )]

#Tower locations 
tower1_lat = np.array ([51.6985630])
tower1_lon = np.array ([-3.3410239])
##
tower2_lat = np.array ([51.6984699])
tower2_lon = np.array ([-3.3400422])
##
tower3_lat = np.array([51.6980743])
tower3_lon = np.array([-3.3406511])

#Your location using the above values
Locaion_Longitude = [tower1_lat * w1 + tower2_lat * w2 + tower3_lat * w3 ]
Locaion_Latitude = [tower1_lon * w1 + tower2_lon * w2 + tower3_lon* w3 ]
print (Locaion_Longitude)
print (Locaion_Latitude)



    
map_fig = plt.imread('map.png')



fig, ax = plt.subplots(dpi=150,figsize = (12,7))



ax.scatter(tower1_lon, tower1_lat, zorder=1, alpha= 0.5, c='red', s=50, label="Tower 1")
ax.scatter(tower2_lon, tower2_lat, zorder=1, alpha= 0.5, c='blue', s=50, label="Tower 2")
ax.scatter(tower3_lon, tower3_lat, zorder=1, alpha= 0.5, c='green', s=50, label="Tower 3")
ax.scatter(Locaion_Longitude, Locaion_Latitude, zorder=1, c='yellow', s=50, label="Your location")


ax.tick_params (axis='y', which='major', labelsize=5)
ax.tick_params (axis='x', which='major', labelsize=5)#axis settings
ax.set_title('Plotting Towers in Aberfan')
ax.set_xlim(BBox[0],BBox[1])
ax.set_ylim(BBox[2],BBox[3])
ax.imshow(map_fig, zorder=0, extent = BBox, aspect= "auto")


mng = plt.get_current_fig_manager() #full screen
mng.window.state("zoomed")

plt.legend()

plt.show()

enter code here

【讨论】:

  • @jtlz2 继承了上面的代码,它正在工作 :) 比链接 pal 的 ks
猜你喜欢
  • 2014-11-04
  • 2022-01-02
  • 2022-09-30
  • 1970-01-01
  • 2012-03-26
  • 1970-01-01
相关资源
最近更新 更多