簡體   English   中英

怎樣讓cartopy人物變大?

[英]How to make a cartopy figure become larger?

我正在使用 Cartopy,我想讓圖像更大。 它有一個很大的legnth,但我希望使寬度更大。 這是我到目前為止的代碼。 我嘗試更改 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(

圖像

要獲得帶有顏色條的地圖圖,您必須指定幾個參數。 這是一個工作代碼,演示了如何設置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()

輸出圖:

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM