1

So I am running this code for plotting a map, and no matter what I try I can't get rid of the ugly box/frame scaled 0 to 1. When I get rid of the figure frame, it refers to the inner one with lat/long that I want to keep.

df = days_dict[t]
    proj = ccrs.PlateCarree()
    ax = plt.axes(projection=proj)
    bounds = [-125.0011, -66.9326, 49.5904, 24.9493]
    ax.set_extent(bounds, crs=ccrs.PlateCarree())

    im = ax.scatter(df['long'], df['lat'], c=df['mean_no2'], s=8, cmap=cm.bwr, vmin=0, vmax=40)
    cartography(ax)
    
    axins = inset_axes(ax, width="90%", height="10%", loc='lower center', borderpad=-3)
    
    cbar = plt.colorbar(im, label='NO2 concentration (ppb)', orientation='horizontal', cax=axins, fraction=0.046, norm=norm, anchor=(0.5, -1))
    cbar.set_ticks(np.arange(0, 40, 10))
    plt.show()
    fig = plt.gcf()
    fig.bbox_inches='tight'
    
    fig.frameon = False
    axins.frameon = False
    out_name = out_folder + '\\frame%s.png' % t
    
    fig.savefig(out_name)
    fig.clear()

I want the inner frame, but not the outer. How can I get rid of this?

enter image description here

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158

2 Answers2

0

The problem arises by the existence of cartography(ax) in your code. Just replace it by this line of code:-

ax.gridlines(xlocs=range(-180,180,10),ylocs=range(-90, 90, 10),color='black',linestyle='dotted',draw_labels=True)
swatchai
  • 17,400
  • 3
  • 39
  • 58
0

Similar issue:

import matplotlib.pyplot as plt
import cartopy.crs as ccrs

proj = ccrs.NorthPolarStereo(true_scale_latitude = 75)
fig, ax = plt.subplots(figsize=(8,6))
ax = plt.axes(projection=proj)
ax.coastlines('10m')
ax.set_extent([-180, 180, 65, 90], crs=ccrs.PlateCarree())

Weird frame

Solution:

fig,ax = plt.subplots(figsize=(8,6), subplot_kw={"projection": ccrs.NorthPolarStereo(true_scale_latitude = 75)})
    ax.coastlines('10m')
    ax.set_extent([-180, 180, 65, 90], crs=ccrs.PlateCarree())

No weird frame

cgxvi
  • 31
  • 4