Colorbar gets overlapped with subplots

After setting the right spacing between the subplots the colorbar gets overlapped with the plots, even though I have used pad keyword in cbar_kwargs.

months = [
    'January', 'February', 'March', 'April', 'May', 'June', 'July',
    'August', 'September', 'October', 'November', 'December',
]
ds_anomalies = ds_mm - ds.ILD_T05.mean(dim='TIME')

pl = ds_anomalies.ILD_T05.plot.contourf(
    levels=20,
    col='month',
    vmax=40,
    vmin=-40,
    col_wrap=3,
    cmap=plt.cm.rainbow,
    cbar_kwargs={
        "label": "MLD in m ", "shrink": 0.8, "aspect": 30, "pad": 0.8
    },
    subplot_kws={"projection": ccrs.PlateCarree()},
)

for i in pl.axes.flat:
    i.coastlines()
    plt.subplots_adjust(
        left=0.1, bottom=0.1, right=0.9, top=0.9, wspace=0.3, hspace=0.3
    )
    i.axes.get_xaxis().set_visible(True)
    i.axes.get_yaxis().set_visible(True)

for i, ax in enumerate(pl.axes.flat): #to give names to the monthly plots 
    current_title = ax.get_title()
    assert current_title[:len('month = ')] == 'month = '
    month_ind = int(current_title[len('month = '):]) - 1
    ax.set_title(months[month_ind])
plt.savefig("fig.pdf")

plots



Comments

Popular posts from this blog

Spring Elasticsearch Operations

Network Error and Timeout on Authorize.net JS

Object oriented programming concepts (OOPs)