请选择 进入手机版 | 继续访问电脑版
爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 11272|回复: 5

[求助] Cartopy中如何设置图的比例

[复制链接]

新浪微博达人勋

发表于 2019-8-8 11:48:04 | 显示全部楼层 |阅读模式

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
今天刚用Cartopy,按照教程中的例子将代码复制粘贴,检验一下是否安装好了。然后发现出的图比例有问题。求解决方法
警告如下:
UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "
C:\Users\asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\tight_layout.py:177: UserWarning: The left and right margins cannot be made large enough to accommodate all axes decorations.
  warnings.warn('The left and right margins cannot be made large '
C:\Users\asus\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\tight_layout.py:182: UserWarning: The bottom and top margins cannot be made large enough to accommodate all axes decorations.
  warnings.warn('The bottom and top margins cannot be made large '

代码
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

# Load the border data, CN-border-La.dat is downloaded from
# http://gmt-china.org/datas/CN-border-La.dat
with open('CN-border-La.dat') as src:
    context = src.read()
    blocks = [cnt for cnt in context.split('>') if len(cnt) > 0]
    borders = [np.fromstring(block, dtype=float, sep=' ') for block in blocks]
# Set figure size
fig = plt.figure(figsize=[10, 8])
# Set projection and plot the main figure
ax = plt.axes(projection=ccrs.LambertConformal(central_latitude=90,
                                               central_longitude=105))
# Add ocean, land, rivers and lakes
ax.add_feature(cfeature.OCEAN.with_scale('50m'))
ax.add_feature(cfeature.LAND.with_scale('50m'))
ax.add_feature(cfeature.RIVERS.with_scale('50m'))
ax.add_feature(cfeature.LAKES.with_scale('50m'))
# Plot border lines
for line in borders:
    ax.plot(line[0::2], line[1::2], '-', color='gray',
            transform=ccrs.Geodetic())
# Plot gridlines
ax.gridlines(linestyle='--')
# Set figure extent
ax.set_extent([80, 130, 13, 55])
# Plot South China Sea as a subfigure
sub_ax = fig.add_axes([0.741, 0.11, 0.14, 0.155],
                      projection=ccrs.LambertConformal(central_latitude=90,
                                                       central_longitude=115))
# Add ocean, land, rivers and lakes
sub_ax.add_feature(cfeature.OCEAN.with_scale('50m'))
sub_ax.add_feature(cfeature.LAND.with_scale('50m'))
sub_ax.add_feature(cfeature.RIVERS.with_scale('50m'))
sub_ax.add_feature(cfeature.LAKES.with_scale('50m'))
# Plot border lines
for line in borders:
    sub_ax.plot(line[0::2], line[1::2], '-', color='gray',
                transform=ccrs.Geodetic())
# Set figure extent
sub_ax.set_extent([105, 125, 0, 25])
# Show figure
plt.show()



OD5OPIF]UGM[FX3MO)YLJX3.png
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2019-8-8 13:59:07 | 显示全部楼层
安装有问题吧,我微调了一下就好了啊
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2019-8-8 15:40:52 | 显示全部楼层
风往北吹 发表于 2019-8-8 13:59
安装有问题吧,我微调了一下就好了啊

请问您是如何解决的?安装我都挺顺利的,没找出什么毛病。谢谢了
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2019-8-8 21:37:59 | 显示全部楼层
xiongxiong1999 发表于 2019-8-8 15:40
请问您是如何解决的?安装我都挺顺利的,没找出什么毛病。谢谢了

https://github.com/matplotlib/matplotlib/issues/5456。根据提醒把matplotlib重新安装到最新的版本试试吧。

WechatIMG3036.png WechatIMG3035.jpeg
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

 楼主| 发表于 2019-8-8 22:31:05 | 显示全部楼层
风往北吹 发表于 2019-8-8 21:37
https://github.com/matplotlib/matplotlib/issues/5456。根据提醒把matplotlib重新安装到最新的版本试试 ...

十分感谢!!
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

新浪微博达人勋

发表于 2023-7-7 10:41:50 | 显示全部楼层
你提供的警告信息是由于图中包含不兼容tight_layout的Axes而导致的。这个警告不会影响图像的比例,但是可能会影响布局。如果你想要解决这个问题,可以尝试调整Axes的大小或位置,或者使用subplots_adjust()方法来调整子图之间的间距。可以尝试使用set_aspect()方法来设置Axes的纵横比。例如,如果你想要一个正方形的图像,可以使用ax.set_aspect(‘equal’)。如果你想要一个特定的纵横比,可以使用ax.set_aspect(‘auto’)和ax.set_box_aspect()方法来设置。1
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表