簡體   English   中英

如何移除 Cartopy/Matplotlib 圖周圍的框架

[英]How to remove the frame around my Cartopy/Matplotlib plot

所以我正在運行這段代碼來繪制地圖,無論我嘗試什么,我都無法擺脫縮放為 0 到 1 的丑陋框/框架。當我擺脫圖形框架時,它指的是內部的我想保留的緯度/經度。

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()

我想要內部框架,而不是外部框架。 我怎樣才能擺脫這個?

在此處輸入圖片說明

問題是由cartography(ax)的存在引起的。 只需刪除它並替換為

ax.gridlines(xlocs=range(-180,180,10),ylocs=range(-90, 90, 10),color='black',linestyle='dotted',draw_labels=True)

類似問題:

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())

奇怪的框架

解決方案:

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())

沒有奇怪的框架

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM