如何使cartoty形象变大?

问题描述 投票:0回答:1

我正在与Cartopy合作,我想放大图像。它的长度很大,但是我希望宽度更大。这是我到目前为止的代码。我尝试更改figsize,但是它只会使颜色栏变大。

fig = plt.figure(figsize=(15,5))
ax = plt.axes(projection=ccrs.PlateCarree())
x = ax.contourf(lon,lat,sum_mag_sq, 30, cmap='RdBu_r')
ax.coastlines()
gridlines = ax.gridlines(draw_labels=True)
cbar = plt.colorbar(x, fraction=.046, pad=0.04)
cbar.set_label('Power Spectrum (m$^2$/# frequencies)', labelpad=15, y=.5, rotation=270)
plt.title('Frequency Summed Power Spectrum (2018-2019)', y=1.2)
plt.show(

cartopy image

python image cartopy
1个回答
0
投票

要获得带有颜色条的地图图,必须指定多个参数。这是一个工作代码,演示如何设置figsizecolorbar的值以获得更好的曲线图。

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

# make up data for plotting
xmin, xmax, ymin, ymax = -55, 15, -4, 4
#extent = [xmin, xmax, ymin, ymax]
width = 4
height = 4
xs = np.linspace(xmin, xmax, width)
ys = np.linspace(ymin, ymax, height)
x2d, y2d = np.meshgrid(xs, ys)
z2d = (x2d+y2d)

fig = plt.figure(figsize=(20,5))  # set figsize (width, height) here
ax = plt.axes(projection=ccrs.PlateCarree())

ct = ax.contourf(x2d, y2d, z2d, 30, cmap='RdBu_r')

ax.coastlines()
gridlines = ax.gridlines(draw_labels=True)

# create a colorbar
cbar = plt.colorbar(ct, fraction=.08, pad=0.04, shrink=0.5, aspect=12)
cbar.set_label('Power Spectrum (m$^2$/# frequencies)', labelpad=15, y=.5, rotation=270)

plt.title('Frequency Summed Power Spectrum (2018-2019)', y=1.2)
plt.show()

输出图:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.