小编Pra*_*tik的帖子

多个最大标记matplotlib

我试图标记多个最大值但无法正确显示它们.此外,标签显示距离与图例重叠的点太远.

import matplotlib.pyplot as plt
import numpy as np

x1,y1= np.loadtxt('MaxMin1.txt', dtype=str, unpack=True)

x1 = x1.astype(int)
y1 = y1.astype(float)

x2,y2= np.loadtxt('MaxMin2.txt', dtype=str, unpack=True)

x2 = x2.astype(int)
y2 = y2.astype(float)

x3,y3= np.loadtxt('MaxMin3.txt', dtype=str, unpack=True)

x3 = x3.astype(int)
y3 = y3.astype(float)

#-------------------------------------------------------------
def annot_max(x,y, ax=None):
    xmax = x[np.argmax(y)]
    ymax = y.max()
    text= "x={:.3f}, y={:.3f}".format(xmax, ymax)
    if not ax:
        ax=plt.gca()
    bbox_props = dict(boxstyle="square,pad=0.3", fc="w", ec="k", lw=0.72)
    arrowprops=dict(arrowstyle="->",connectionstyle="angle,angleA=0,angleB=60")
    kw = dict(xycoords='data',textcoords="axes fraction",
              arrowprops=arrowprops, bbox=bbox_props, ha="left", va="top")
    ax.annotate(text, xy=(xmax, ymax), xytext=(0.94,0.96), **kw)


#-------------------------------------------------------------

fig=plt.figure()
fig.show() …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

5
推荐指数
1
解决办法
286
查看次数

使用 Google API 进行反向地理编码的 Python 代码

我正在 json 文件 (geo.json) 中获取地理数据,该文件具有以下结构

 {"userId":"Geo-data","data":{"mocked":false,"timestamp":1548173963281,"coords":{"speed":0,"heading":0,"accuracy":20.20400047302246,"longitude":88.4048656,"altitude":0,"latitude":22.5757344}}}
Run Code Online (Sandbox Code Playgroud)

我想要的只是打印与上述数据相对应的地点详细信息,如果可能的话,也将其显示在地图上。我已使用 geopy 尝试了以下代码

from geopy.geocoders import Nominatim
geolocator = Nominatim()
location = geolocator.reverse("22.5757344, 88.4048656")
print(location.address)
print((location.latitude, location.longitude))
Run Code Online (Sandbox Code Playgroud)

但我得到的位置不是很准确。虽然相同的坐标在https://www.latlong.net/Show-Latitude-Longitude.html中给出了良好的结果 ,但我也有一个 Google API 密钥。然而,到目前为止我发现的参考资料几乎就像一个项目本身,对于像我这样的初学者来说有点过分了。geopy 代码很好,但定位精度很差。请帮忙。

PS我也尝试过地理编码器

import geocoder
g = geocoder.google([45.15, -75.14], method='reverse')
print(g.city)
print(g.state)
print(g.state_long)
print(g.country)
print(g.country_long)
Run Code Online (Sandbox Code Playgroud)

然而,它在所有情况下都打印“无”。

google-maps reverse-geocoding python-2.7

4
推荐指数
2
解决办法
1万
查看次数