【问题标题】:Cartopy figsize does not change the actual size of the mapcartopy figsize 不会改变地图的实际大小
【发布时间】:2018-05-13 00:16:13
【问题描述】:

使用cartopy时如何改变图形的宽高。 figsize 仅更改图形周围的空白区域,而不更改图形本身。有任何想法吗。

import cartopy.crs as ccrs 
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

def main():
    fig = plt.figure(figsize=(10,10))
    ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())
    ax.set_extent([-20, 60, -40, 45], crs=ccrs.PlateCarree())

    ax.add_feature(cfeature.LAND)
    ax.add_feature(cfeature.OCEAN)
    ax.add_feature(cfeature.COASTLINE)
    ax.add_feature(cfeature.BORDERS, linestyle=':')
    ax.add_feature(cfeature.LAKES, alpha=0.5)
    ax.add_feature(cfeature.RIVERS)

    plt.show()

if __name__ == '__main__':
    main()

这个代码在here找到

【问题讨论】:

  • 在 Cartopy 中执行几个步骤即可。但不是像 Basemap 这样的单一语句。
  • 谢谢,知道怎么做吗?
  • 您的问题已经改变。我上面的评论现在无效了。

标签: python python-3.x python-2.7 matplotlib cartopy


【解决方案1】:

地图的大小只能通过set_extent() 方法由它的范围来定义。更改figsize 只会影响地图轴周围的白框。

编辑

如果您想放大地图而不更改其范围,我只看到一个选项:更改投影。这里有一些例子:

如您所见,一些投影会增加高度,而另一些则会显得更宽。您无法完全控制地图的宽高比,但您仍然可以尝试查看某些投影是否更适合您。

您可以在https://scitools.org.uk/cartopy/docs/v0.15/crs/projections.html 找到投影列表。

这是生成第一张图片的代码:

import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt

fig = plt.figure(figsize=(3, 3))

ax = fig.add_subplot(1, 1, 1, projection=ccrs.LambertCylindrical())
ax.set_extent([-20, 60, -40, 45])
ax.add_feature(cfeature.LAND)
ax.add_feature(cfeature.OCEAN)
ax.add_feature(cfeature.COASTLINE)
ax.add_feature(cfeature.BORDERS, linestyle=':')
ax.add_feature(cfeature.LAKES, alpha=0.5)
ax.add_feature(cfeature.RIVERS)
ax.set_title('LambertCylindrical')

plt.savefig('LambertCylindrical.png', dpi=100)

【讨论】:

  • 非常感谢您的帮助。我试图只绘制热带地区,但我也想在不超出热带地区的情况下放大地图。有什么方法可以在不增加经纬度扩展的情况下扩大特定域?
  • 非常感谢。我认为 Cartopy 在控制图像宽度和高度的底图函数(basemaptutorial.readthedocs.io/en/latest/basemap.html)中有一些参数,例如宽度和高度。我认为如果 Cartopy 具有类似的功能会很好。谢谢
  • 查看以下更全面的解决方案。 github.com/SciTools/cartopy/issues/1074
猜你喜欢
  • 1970-01-01
  • 2019-02-15
  • 1970-01-01
  • 2013-09-08
  • 2021-09-11
  • 2016-04-17
  • 2015-03-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多