- 散点图,每个bin 中画一段线
from scipy import stats
bins=[3.5,4,4.5,5,5.5,6,6.5]
x,y=L_shell,ne
plt.scatter(x,y,s=25,c='b')
bin_medians, bin_edges, binnumber = stats.binned_statistic(x,y,statistic='median', bins=bins)
plt.hlines(bin_medians,bin_edges[:-1],bin_edges[1:],label='median')
for i in range(len(bin_medians)):
xvar=[bin_edges[i],bin_edges[i+1]]
yvar=[bin_medians[i],bin_medians[i]]
plt.plot(xvar,yvar,'-',color='red')
定义colorbar 的位置
now we determine colorbar location
img=ax.pcolormesh(t, w, psd, vmin = vmin, vmax=vmax,cmap=purula(), norm='log', rasterized = True)
ax_pos_ul = axes[0,-1].get_position()
ax_pos_ll = axes[1,-1].get_position()
cb_height = ax_pos_ul.ymax-ax_pos_ll.ymin
cb_width = 0.015
hspace = 0.025
x0 = ax_pos_ll.xmax + hspace
y0 = ax_pos_ll.ymin
x1 = x0 + cb_width
cbp = [x0, y0, cb_width, cb_height]
cax = fig.add_axes(cbp)
clb = plt.colorbar(img, label=r'P$_B$ $(B_0^2/\Omega_{e0})$', cax=cax)
clb.set_ticks([cbar_var[0],cbar_var[40],cbar_var[-1]])
clb.set_ticklabels([Time_string_hhmm[0],Time_string_hhmm[40],Time_string_hhmm[-1]])
全局变量的一些参数
matplotlib.rc('font',size=7)
matplotlib.rcParams['axes.linewidth'] = 1
matplotlib.rcParams['xtick.major.width'] = 1
matplotlib.rcParams['xtick.minor.width'] = 0.8
matplotlib.rcParams['xtick.major.size'] = 2.5
matplotlib.rcParams['xtick.minor.size'] = 1.8
matplotlib.rcParams['ytick.major.width'] = 1
matplotlib.rcParams['ytick.minor.width'] = 0.8
matplotlib.rcParams['ytick.major.size'] = 2.5
matplotlib.rcParams['ytick.minor.size'] = 1.8
matplotlib.rcParams['pdf.fonttype'] = 42
matplotlib.rcParams['ps.fonttype'] = 42
python下面加上几行MLT,mlat,L等参数,类似IDL的图
xtick_pos=[]
xtick_lb=[]
x_index=[]
mlat_lb=[];mlt_lb=[]
for i in range(len(time_xtick)):
bYear=time_xtick[i].year;bMonth=time_xtick[i].month;bDay=time_xtick[i].day
bUThh=time_xtick[i].hour;bUTmm=time_xtick[i].minute;bUTss=time_xtick[i].second
bEpoch=1e3*time_xtick[i].replace(tzinfo=datetime.timezone.utc).timestamp()
#bEpoch=cdflib.cdfepoch.compute([int(bYear),int(bMonth),int(bDay),int(bUThh),int(bUTmm),int(bUTss),0])
delta_epoch=(aTime-bEpoch)
#fp=np.where(delta_epoch==min(delta_epoch))# find a time which is close to the tick
fp=np.where(delta_epoch>=0)
#if i==1: sys.exit()
time_index=int(fp[0][0])
x_index.append(time_index)
cDateTime=datetime.datetime.utcfromtimestamp(aTime[time_index]/1e3)
cUThh=cDateTime.hour;cUTmm=cDateTime.minute;cUTss=cDateTime.second
xtick_pos.append(aTime[time_index])
xtick_lb.append(numlib.num2str(cUThh,2)+':'+numlib.num2str(cUTmm,2)+':'+numlib.num2str(cUTss,2))
mlat_lb.append(aMlat[time_index])
mlt_hh,mlt_mm,mlt_ss=numlib.hhmmss(aMlt[time_index])
mlt_lb.append(mlt_hh+':'+mlt_mm)
#bPosX.append(Xgsm[time_index]);
#bPosY.append(Ygsm[time_index]);
#bPosZ.append(Zgsm[time_index])
for i in range(len(xtick_lb)):
hf[axes_num].text(x=x_index[i]/len(aTime),y=-0.1,s=xtick_lb[i][0:5],color='k',fontsize=LabelSize-1,ha='center',va='center',transform=hf[axes_num].transAxes)
hf[axes_num].text(x=x_index[i]/len(aTime),y=-0.2,s=np.round(mlat_lb[i],1),color='darkcyan',fontsize=LabelSize-1,ha='center',va='center',transform=hf[axes_num].transAxes)
hf[axes_num].text(x=x_index[i]/len(aTime),y=-0.3,s=mlt_lb[i],color='m',fontsize=LabelSize-1,ha='center',va='center',transform=hf[axes_num].transAxes)
hf[axes_num].text(x=-0.13,y=-0.1,s='UT',color='k',fontsize=LabelSize-1,va='center',transform=hf[axes_num].transAxes)
hf[axes_num].text(x=-0.13,y=-0.2,s='MLAT',color='darkcyan',fontsize=LabelSize-1,va='center',transform=hf[axes_num].transAxes)
hf[axes_num].text(x=-0.13,y=-0.3,s='MLT',color='m',fontsize=LabelSize-1,va='center',transform=hf[axes_num].transAxes)
for i in range(len(hf)):
hf[i].text(x=0.05,y=0.92,s=panel_label[i],color='red',fontsize=LabelSize,ha='center',va='center',transform=hf[i].transAxes)