Abeda
Abeda

Reputation: 1

Draw opaque rectangle on basemap

I want to draw the rectangle on top of my basemap and place the quiverkey on the rectangle. My code is the following:

For Basemap:

def getBM(ax,suppress_ticks):
     m1 = Basemap(projection='lcc', lat_0 = 23.72,lon_0 = 90.40 ,resolution = 'l',
          urcrnrlat=29, llcrnrlat=19, llcrnrlon=85,urcrnrlon=95.5,
          ax=ax, fix_aspect=False,
          suppress_ticks=suppress_ticks)

     m1.drawcoastlines(color='black',linewidth = 2)
     m1.drawcountries(linewidth = 2)

     return m1

For drawing rectangle and quiverkey:

cm      = 1/2.54
n_px    = 1 
n_py    = 3
figure, ax = plt.subplots(n_py, n_px, figsize = (32*cm,32*cm),gridspec_kw = dict(height_ratios = [1,1,1], width_ratios = [1]))

ax[0].quiverkey(Q,0.85,0.95,5,label = '5 m s$^{-1}$', color = 'black', labelpos = 'S',fontproperties={'size':12}, coordinates='axes',zorder = 7)

rect =  patches.Rectangle(xy=(0.7,0.8), width=0.3, height=0.2, transform=ax[0].transAxes,edgecolor='black', facecolor = 'white', clip_on=False, alpha=1) 

ax[0].add_patch(rect)

As you can see the top right box and quiver and basemap line. I want to remove the basemap line from the rectangle fig1

The problem is, when I use zorder = 2 or higher in rectangle, both the basemap and quiverkey goes underneath the rect. If I use zorder = 1 or less, basemap and quiverkey are both over the rect. I tried using zorder = 10 for quiverkey but it doesn't make the key go above the rect. I am not sure if I explained it well. I checked this answer Background color of quiverkey in matplotlib however they didn't resolve the issue.

Can anyone help me with this?

I am expecting something like fig2

Upvotes: 0

Views: 90

Answers (0)

Related Questions