- 积分
- 65
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2018-10-24
- 最后登录
- 1970-1-1
|
GrADS
系统平台: |
|
问题截图: |
- |
问题概况: |
如何修改经纬度坐标文本显示位置 |
我看过提问的智慧: |
看过 |
自己思考时长(天): |
1 |
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 黄45 于 2023-10-5 21:03 编辑
请教各位大佬,如何修改以下代码将下图中红色的经度文本放置到方框(模拟域)下方位置。
#import module
import numpy as np
import cartopy
import matplotlib.pyplot as plt
from cartopy import crs
from cartopy.feature import NaturalEarthFeature,COLORS
import cartopy.io.shapereader as shapereader
from cartopy.mpl.gridliner import LATITUDE_FORMATTER,LONGITUDE_FORMATTER
import matplotlib.ticker as mticker
from matplotlib.cm import get_cmap
from matplotlib.colors import from_levels_and_colors
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
from xarray import DataArray
from wrf import getvar, interplevel, vertcross, vinterp, ALL_TIMES, CoordPair, xy_to_ll,\
ll_to_xy, to_np, get_cartopy, latlon_coords, cartopy_xlim, cartopy_ylim
from netCDF4 import Dataset as nd
import os
import warnings
warnings.filterwarnings('ignore')
#read file data
wrf_dir = "/mnt/w_test4/"
wrf_file = ["wrfout_d01_2020-03-01_00.nc",
"wrfout_d01_2020-03-11_00.nc",
"wrfout_d01_2020-03-21_00.nc",]
wrf_files = [os.path.abspath(os.path.join(wrf_dir,f)) for f in wrf_file]
for f in wrf_files:
if not os.path.exists(f):
raise ValueError("{} does not exist."
"check for typos or incorrect directory.".format(f))
def single_wrf_file():
global wrf_files
return wrf_files[0]
def multiple_wrf_files():
global wrf_files
return wrf_files
file_path = single_wrf_file()
wrf_f = nd(file_path)
terrain = getvar(wrf_f, "ter", timeidx = 0)
cart_proj = get_cartopy(terrain)
lats, lons = latlon_coords(terrain)
#叠加中国地图
china = "/home/hsy/03-datadownload/shpdata/china-boundary/china-boundary.shp"
extent = [70, 140, 10,60] #限定绘图范围
cart_proj = get_cartopy(terrain) #创建投影,对应数据集中terrain的投影
#https://github.com/SciTools/cartopy/issues/1937
fig = plt.figure(figsize=(10,8))
geo_axes = plt.axes(projection=cart_proj)
states = NaturalEarthFeature(category='cultural',
scale='50m',
facecolor='none',
name='admin_1_states_provinces')
cmap = cartopy.feature.ShapelyFeature(shapereader.Reader(china).geometries(), cart_proj, edgecolor="k", facecolor="none", linewidth=1)
geo_axes.add_feature(cmap, linewidth=0.8)
geo_axes.add_feature(states, linewidth=0.9)
geo_axes.coastlines("50m", linewidth = 0.8)
levels = np.arange(1, 8000, 500)
plt.contour(to_np(lons), to_np(lats), to_np(terrain),
levels=levels, colors="black", transform = crs.PlateCarree())
plt.contourf(to_np(lons), to_np(lats),
to_np(terrain), levels=levels,
transform=crs.PlateCarree(),
cmap=get_cmap("jet"))
#添加经纬度坐标系
plt.rcParams["font.sans-serif"]=["SimHei"]
gl = geo_axes.gridlines(draw_labels = True, linestyle=":", linewidth=1, color="grey")
gl.top_labels = False #关闭上部经纬度标签
gl.right_labels = False
gl.xlabels_bottom = True
gl.xformatter = LONGITUDE_FORMATTER #使横坐标转化为经纬度格式
gl.yformatter = LATITUDE_FORMATTER
gl.xlocator = mticker.FixedLocator(np.arange(70,140,10))
gl.ylocator = mticker.FixedLocator(np.arange(10,60,10))
gl.xlabel_style ={"size":12, "color":"red"} #修改经纬度坐标网格字体大小
gl.ylabel_style ={"size":12, "color":"black"} #修改经纬度坐标网格字体大小
plt.colorbar(ax=geo_axes, shrink=0.58)
#plt.show()
plt.savefig("../wrf-domain.jpg", dpi = 600)
|
-
|