我想增加由使用 matplotlib 库在 Bing 地图上绘制的多边形组成的绘图的缩放级别。我正在使用以下代码:
import requests
from PIL import Image
from io import BytesIO
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import matplotlib.pyplot as plt
plt.style.use('default')
# matplotlib.use('Agg')
API_KEY = "<api key"
poly_str = [(26.258654470488352, 50.60623948760518), (26.260892838025025, 50.61137614053575), (26.259367564324837, 50.612537537528866), (26.257912032768143, 50.615014721155816), (26.257639268464615, 50.60718484036582)]
# Coordinates for the center of the map
center_lat1 = sum([coord[0] for coord in poly_str])
center_lon1 = sum([coord[1] for coord in poly_str])
center_lat = center_lat1/len(poly_str)
center_lon = center_lon1/len(poly_str)
print(f"Centroid Latitude: {center_lat}")
print(f"Centroid Longitude: {center_lon}")
# Static map parameters
zoom_level = 16
map_size = '4000,4000'
# Bing Maps API URL
map_url = f"http://dev.virtualearth.net/REST/v1/Imagery/Map/Road/{center_lat},{center_lon}/{zoom_level}?mapSize={map_size}&format=png&key={API_KEY}"
# Fetch the static map image
response = requests.get(map_url)
image = Image.open(BytesIO(response.content))
# Display the map using matplotlib
fig, ax = plt.subplots(figsize=(8, 8),dpi=200)
ax.imshow(np.asarray(image), extent=[0, image.width, 0, image.height])
polygon_coords =[(841, 678), (1086, 665), (1084, 573), (1006, 471), (866, 586)]
print(polygon_coords)
plt.axis('off')
plt.show()
# plt.savefig("map_bing.jpg")
放置
zoom_level = 15
时,我得到以下图像:
一旦我改变
zoom_level = 16
或更多,我就会得到以下图像:
如何在更改缩放级别时保持背景颜色不变?
我 100% 同意@rbrundritt。最好将解决方案迁移到 Azure Maps。 Microsoft 已发布此页面,这是从 Bing Enterprise Maps 迁移到 Azure Maps 的网关,包括指向迁移指南的链接。