- 积分
- 3400
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-4-21
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
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()
|
-
|