簡體   English   中英

Cartopy 因極地地區的小區域地塊而失敗

[英]Cartopy fails with small regional plots in polar regions

我想制作簡單的靜態地圖以用於期刊論文。 我在北極工作,制作了大量地圖圖像,顯示設備布局、船只軌跡以及源和接收器位置。 我不能在 CARTOPY 中做到這一點。 例如,1 度緯度(74 到 75N)和 2.5 度經度(-92.5 到 -90.0)在 74.5N 的中緯度。 你不能讓海岸線正常工作。 該地圖通常是空的,但它應該顯示 NU 德文島的一部分海岸線。 如果我將繪圖設為更大的區域(例如 30 度乘 30 度),它會起作用,但您會看到圖形窗口中顯示的坐標未正確對齊。 X、Y 值與圖形軸匹配,但括號中的 lat、lon 值已移動。 在最壞的情況下,緯度、經度出現 0.00n 度甚至近半個地球。

我嘗試了多種調用范圍的方法。 不同的預測。 似乎沒有任何效果。

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import cartopy.crs as ccrs
import matplotlib.pyplot as plt
from cartopy.feature import NaturalEarthFeature
from cartopy.mpl.ticker import LongitudeFormatter, LatitudeFormatter
import numpy as np
import matplotlib.ticker as mticker


# the limits of the map
# extent = (-100., -50.0, 60.0, 80.0)  # try this, you'll get a shifted plot on northern Alaska
extent = (-92.5, -90.0, 74.0, 75.0)   # try this, you'll get a blank plot. axes shifted badly.

# set the projection type
c_lon, c_lat = (extent[0] + extent[1])/2., (extent[2] + extent[3])/2.
proj = ccrs.PlateCarree(central_longitude=c_lon)
# proj = ccrs.Mercator(c_lon)    # I've tried these as well
# proj = ccrs.Orthographic(c_lon, c_lat)

gax = plt.axes(projection=proj)
gax.set_extent(extent)
gax.set_ylim((extent[2], extent[3]))
gax.set_xlim((extent[0], extent[1]))

# now add the coastline. This only works for big maps. Small regions fail.
coastline_10m = NaturalEarthFeature(category='physical', name='coastline', \
                    facecolor='none', scale='10m')
gax.add_feature(coastline_10m, edgecolor='gray')

# draw a grid with labelled lat and lon. Suppress ticklabels on the top and right.
gl = gax.gridlines(crs=proj, draw_labels=True) # only works with PlateCarree()
gl.xlabels_top = None
gl.ylabels_right = False

# now we put labels on the X and Y axes. You have to move these around manually.
gax.text(-0.2, 0.55, 'Latitude [Deg]', va='bottom', ha='center',
        rotation='vertical', rotation_mode='anchor',
        transform=gax.transAxes)
gax.text(0.5, -0.12, 'Longitude [Deg]', va='bottom', ha='center',
        rotation='horizontal', rotation_mode='anchor',
        transform=gax.transAxes)

# approximately correct for the aspect ratio
plt.gca().set_aspect(1.0/(np.cos(np.pi*(extent[2] + extent[3])/(2.*180.))))
plt.show()

macOS Catalina、Anaconda python3.8.3、IPython 7.19.0、cartopy 0.17(支持的最高版本。Anaconda 說是 0.18,但它安裝了 0.17)。

一些明顯的錯誤:

  1. set_extent()需要選項crs=ccrs.PlateCarree()
  2. set_xlim()set_ylim需要數據(地圖投影)坐標。

set_xlim()set_ylim改變了你在上一行中對set_extent()所做的事情。 必須正確使用它們。 大多數情況下,不應使用它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM