1

I am trying to save a png image using the following commands:

fig = plt.figure(figsize=(14, 8))

ax1 = fig.add_subplot(221)
subplt1=(usub1_sfc-usub2_sfc).plot(vmin=-2.5e-2,vmax=2.5e-2,add_colorbar=False)
cb=plt.colorbar(subplt1,extend='both')
cb.ax.set_title('m/s', size=14)
cb.ax.tick_params(labelsize=12)
ax1.tick_params(labelsize=12)
ax1.set_xticks(np.arange(0,3500,500))
ax1.set_yticks(np.arange(0,2500,500))
#plt.xticks(fontsize=10)
#fig.colorbar(subplt1)
plt.title('USUBM$_{\mathrm{1km}}$ - USUBM$_{\mathrm{5km}}$')
plt.xlabel('nlon',fontsize=16)
plt.ylabel('nlat',fontsize=16)


ax2 = fig.add_subplot(222)
subplt2=(usub3_sfc-usub2_sfc).plot(vmin=-2.5e-2,vmax=2.5e-2,add_colorbar=False)
cb=plt.colorbar(subplt2,extend='both')
cb.ax.set_title(label='m/s', size=14)
cb.ax.tick_params(labelsize=12)
ax2.tick_params(labelsize=12)
ax2.set_xticks(np.arange(0,3500,500))
ax2.set_yticks(np.arange(0,2500,500))
plt.title('USUBM$_{\mathrm{200m}}$ - USUBM$_{\mathrm{5km}}$')
plt.xlabel('nlon',fontsize=16)
plt.ylabel('nlat',fontsize=16)

fig.savefig('./test.png',dpi=130)

My png file ends up having a checkerboard pattern everywhere around the bounding boxes of the plots. Inside the boxes I can see the fields, but everywhere around it the checkerboard pattern covers the axis ticks, axis labels, plot titles, etc.

The file I create looks very much like the third image at this link. The only difference is that there you see the checkerboard everywhere.

Question: How to save the png image without this checkerboard pattern?

  • This got resolved, thanks to this thread: https://urldefense.com/v3/__https://stackoverflow.com/questions/44807656/using-plt-show-how-can-i-define-the-background-color__;!!KwNVnqRv!R1PAu8EJswkU3dxwsyMCXWo0f59T5oqRhaln7Qewhf7jJ1zCUlyZaIhiIWbBUHo$ –  Mar 12 '21 at 02:04
  • Great to see that this got solved. If you have the solution, post it and mark as answered. Or you can close the question itself. – Joe Ferndz Mar 16 '21 at 05:12

1 Answers1

1

Here is the answer to my original question (based on the other thread I linked to):

fig = plt.figure(facecolor="w")

This removed the checkerboard pattern surrounding the plotted area.