![](/img/trans.png)
[英]Placement of latitude labels in cartopy with polar stereographic projection
[英]How do I get smooth gridlines in cartopy polar stereographic plots with matplotlib?
使用matplotlib和cartopy的NorthPolarStereo投影進行繪圖時,恆定緯度網格線(平行線)不是平滑圓。
這是一個最小的工作示例:
from matplotlib import pyplot
import cartopy.crs
ax = pyplot.axes(projection=cartopy.crs.NorthPolarStereo())
ax.set_extent((-180, 180, 60, 90), crs=cartopy.crs.PlateCarree())
ax.gridlines()
pyplot.show()
如您所見,平行線是點之間的一系列直線段。 每條線上沒有足夠的點使它們看起來光滑。 如何使平行線更圓?
問:如何使平行線更圓?
答:您需要更大的gridlines()
創建的gridliner
對象的n_steps
屬性值。 它的默認值是30.這是將值設置為90的相關代碼,並生成更好的繪圖。
gl = ax.gridlines(draw_labels=False, xlocs=None, ylocs=None)
gl.n_steps = 90
見這里的參考。
樣本輸出:
這是由於此用例的默認閾值太大。 這不是Cartopy投影界面的用戶可控部分。 你可以使用private _threshold
屬性來破解它,將它除以100對你的用例來說是合理的:
from matplotlib import pyplot
import cartopy.crs
hacked_proj = cartopy.crs.NorthPolarStereo()
hacked_proj._threshold /= 100.
ax = pyplot.axes(projection=hacked_proj)
ax.set_extent((-180, 180, 60, 90), crs=cartopy.crs.PlateCarree())
ax.gridlines()
pyplot.show()
這不是一個很好的解決方案,因為它使用了Stereographic
類的實現細節,最好在Cartopy中更好地設置它。 使用此用例在Cartopy Github倉庫上打開票證將是一個很好的開始https://github.com/SciTools/cartopy/issues 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.