def meter_box(axin,loc,dist,color='k',lw=1,retbox=False): """ Given axes and location in lon/lat and a distance (1d or 2d) in meters plots a box around that location. NOTE: This uses my hacky ll_dist, so will be correct over small region but not as accurate over large regions. :Parameters: axin - The axes to plot the box on. loc - The center of the box being plotted. dist - The distance in meters around the box to plot. """ dist=np.atleast_1d(np.array(dist)) loc=np.array(loc) tr={} tr['region']=np.array([loc[0],loc[0],loc[1],loc[1]]) lon_space=pjt.ll_dist(tr,dist[0]) if len(dist)==2: lat_space=dist[1]/111120 else: lat_space=dist[0]/111120 tr['region'][0]=tr['region'][0]-lon_space tr['region'][1]=tr['region'][1]+lon_space tr['region'][2]=tr['region'][2]-lat_space tr['region'][3]=tr['region'][3]+lat_space plot_box(axin,tr,color=color,lw=lw) if retbox==True: return tr['region']
def scalebar(axin,region,dist,**kwargs): """ Given axes, region, and distance plots a scalebar. NOTE: Must be called AFTER prettyplot_ll or ppll_sub as the aspect ratio must be set first. :Parameters: axin - The axes to plot the box on. region - The region being plotted. dist - The distance in meters of the scalebar. **loc - Where to place the scalebar (only one option for now, lower left). **fontsize - Text fontsize (default - 8). **color - Color of scalebar and text (default - 'k'). **label - Override label. """ fontsize=8 loc=0 color='k' lw=1 if dist<1000: label=("%d"%dist)+' m' else: label=("%.1f"%(dist/1000))+' km' drawn=False if kwargs is not None: for key, value in kwargs.iteritems(): if (key=='fontsize'): fontsize=value if (key=='loc'): loc=value if (key=='color'): color=value if (key=='label'): label=value if (key=='lw'): lw=value if (key=='drawn'): drawn=value if drawn==False: plt.draw() ftrans=axin.get_figure().transFigure dinv=axin.transData.inverted() if loc==0: lldist=pjt.ll_dist(region,dist) axbb=axin.get_axes().get_position().bounds t=axin.annotate(label,xy=(axbb[0]+.02,axbb[1]+.0275),xycoords='figure fraction',fontsize=fontsize,color=color) t.set_zorder(100) xtmp,ytmp=dinv.transform(ftrans.transform((axbb[0]+.02,axbb[1]+.02))) axin.plot([xtmp,xtmp+lldist],[ytmp,ytmp],color=color) if loc==2: lldist=pjt.ll_dist(region,dist) axbb=axin.get_axes().get_position().bounds t=axin.annotate(label,xy=(axbb[0]+axbb[2]-.085,axbb[1]+axbb[3]-.0225),xycoords='figure fraction',fontsize=fontsize,color=color) t.set_zorder(100) xtmp,ytmp=dinv.transform(ftrans.transform((axbb[0]+axbb[2]-.085,axbb[1]+axbb[3]-.03))) axin.plot([xtmp,xtmp+lldist],[ytmp,ytmp],color=color)