登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 dragonphy 于 2021-3-9 20:19 编辑
用pythoncartopy畫zoominto子圖之間的連結線
import matplotlib.pyplot as plt import numpy as np import cartopy.crs from matplotlib.axes import Axes from matplotlib.patches import Rectangle import matplotlib.gridspec as gridspec import matplotlib.patches as patches
csfont ={'family':'serif','style':'normal','weight':'semibold'} G3x=[116.895, 117.436, 117.436, 116.895, 116.895] G3y=[35.9754, 35.9754, 36.5198, 36.5198, 35.9754] G2x=[116.418, 117.779, 117.779, 116.418, 116.418] G2y=[35.5905, 35.5905, 36.9043, 36.9043, 35.5905] ############ latt =['(b)','(a)'] fig = plt.figure(figsize=(10*1.618,10),constrained_layout=True) fig.canvas.mpl_connect('resize_event',lambda v: line.recache()) gs = gridspec.GridSpec(1,2,width_ratios=[3,4]) pj=cartopy.crs.Stereographic(central_latitude=(36.2556),central_longitude=(117.1053)) pc =cartopy.crs.PlateCarree() ax={} ############################### (b)subfig outter domain ########################### ax[0]=plt.subplot(gs[1],projection = pj) ax[0].set_extent([114.412,120.588,34.0527,38.9473],crs=pc) ax[0].text(0.01,0.995,latt[0],transform=ax[0].transAxes,fontsize=16,va='top',ha='left',**csfont) scale_bar(ax[0], (0.1, 0.05), 40, text_kwargs={'family':'serif'}) ############ boxes G2, G3 ############# ax[0].fill(G2x,G2y,facecolor='none',edgecolor='black',linewidth=1,transform=pc) ax[0].fill(G3x,G3y,facecolor='none',edgecolor='black',linewidth=1,transform=pc) ax[0].text(116.418,36.9043,'G2',color='black',transform=pc,fontsize=18,**csfont,ha='left',va='bottom') ax[0].text(116.895,36.5198,'G3',color='black',transform=pc,fontsize=15,**csfont,ha='left',va='bottom') ############# grid setting ############ g1 = ax[0].gridlines(draw_labels=True, dms=False, x_inline=False, y_inline=False, linestyle='--',color='xkcd:light grey') g1.xlabel_style = {'size':12,'family':'serif'} g1.ylabel_style = {'size':12,'family':'serif'} g1.right_labels = False g1.top_labels = False ############################# (a)subfiginner domains ########################## ax[1] = plt.subplot(gs[0],projection = pj) ax[1].set_extent([116.418, 117.779, 35.5905,36.9043],crs=pc) ax[1].text(0.01,0.995,latt[1],transform=ax[1].transAxes,fontsize=16,va='top',ha='left',**csfont,c='white') scale_bar(ax[1], (0.1, 0.05), 10, text_kwargs={'family':'serif'}) ############ boxes G2, G3############# ax[1].text(116.895,35.9754,'G3',color='black',transform=pc,fontsize=17,**csfont,ha='left',va='bottom') ax[1].fill(G3x,G3y,facecolor='none',edgecolor='black',linewidth=0.8,transform=pc) ############# grid setting ############ g2 = ax[1].gridlines(draw_labels=True, dms=False, x_inline=False, y_inline=False, linestyle='--',color='xkcd:light grey') g2.xlabel_style = {'size':12,'family':'serif'} g2.ylabel_style = {'size':12,'family':'serif'} g2.xlocator =matplotlib.ticker.FixedLocator([116.5,117.0,117.5]) g2.ylocator =matplotlib.ticker.FixedLocator([35.6,36.0,36.4,36.8]) g2.right_labels = False g2.top_labels = False ############################################################################### xyA = pj.transform_point(117.779,36.9043,pc) xyB = pj.transform_point(117.779,35.5905,pc) con1 =patches.ConnectionPatch(xyA=xyA,xyB=xyA,coordsA=ax[0].transData,coordsB=ax[1].transData,linestyle='--') con2 =patches.ConnectionPatch(xyA=xyB,xyB=xyB,coordsA=ax[0].transData,coordsB=ax[1].transData,linestyle='--') fig.add_artist(con1) fig.add_artist(con2) fig.tight_layout() fig.subplots_adjust(wspace=0.1) plt.show() [說明]:
|