如何只绘制一堆圆圈的轮廓

问题描述 投票:0回答:1

我正在尝试绘制我创建的几个圆圈的轮廓 - 并且仅是轮廓。到目前为止,这是我的代码:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from matplotlib.patches import PathPatch
from matplotlib.path import Path
import matplotlib.ticker as mticker
import numpy as np

# Koordinaten des gewünschten Ausschnitts
lon_west = 17
lon_east = 35
lat_south = 57
lat_north = 70
proj = ccrs.PlateCarree()

plt.figure(figsize=(16, 10))
ax = plt.axes(projection=ccrs.Orthographic(central_longitude=24.3, central_latitude=61.83, globe=None))
ax.set_extent([lon_west, lon_east, lat_south, lat_north], crs=proj)

# Hinzufügen von Eigenschaften zu der Karte
ax.coastlines(linewidth=.5)
ax.add_feature(cfeature.LAND, color='gray', alpha=.15)
ax.add_feature(cfeature.BORDERS, linestyle='-', linewidth=.6)

# Zeichne Meridiane und Breitenkreise
gl = ax.gridlines(draw_labels=True, linewidth=.5, color='gray', alpha=.5, linestyle='-.')
gl.ylocator = mticker.FixedLocator([57, 60, 63, 66])
gl.top_labels = False
gl.left_labels = False

# Definition der Reichweite und die Koordinaten
radius = 250  # km
lons = (21.64, 22.5, 23.82, 24.5, 25.44, 26.32, 26.9, 27.11, 27.38, 29.45, 29.8)
lats = (60.13, 61.81, 63.1, 60.56, 62.3, 64.77, 67.14, 60.9, 62.86, 63.84, 61.91)

# Hinzufügen der Koordinaten und Reichweite der Radarstationen
for lon, lat in zip(lons, lats):
    theta = np.linspace(0, 2 * np.pi, 100)
    x = lon + radius * 1000.0 * np.cos(theta)
    y = lat + radius * 1000.0 * np.sin(theta)

    path_data = np.column_stack([x, y])
    codes = [Path.MOVETO] + [Path.LINETO] * (len(x) - 1)
    path = Path(path_data, codes)

    patch = PathPatch(path, transform=ccrs.PlateCarree(), edgecolor="black", lw=0.5, linestyle="--", facecolor='none')
    ax.add_patch(patch)
    ax.scatter(lon, lat, color='black', marker='o', s=2, transform=proj)

plt.show

我已经在网上搜索过,但到目前为止找不到解决方案。如果有人可以帮助我,那就太好了:)

python matplotlib cartopy
1个回答
1
投票

你实际上并没有提到问题是什么,所以很难回答。

但是您目前可能无意中做的事情是混合不同的单位来创建您的圆圈。您将地图定义为正交地图,中心以纬度/经度为单位,半径以米为单位。你期望的结果是什么?

假设您指定具有

PlateCarree()
投影的圆,则半径也应如此定义。在您当前的代码中,一切正常,但您将半径设置为 250000 Degrees !!

例如,如果将半径设置为 2.5 度,则如下图所示:

您必须决定是否希望圆成为地球上的圆(大地测量)、地图投影上的圆或图像上的圆(图形坐标)等。然后以一致的方式相应地选择单位。

© www.soinside.com 2019 - 2024. All rights reserved.