Ticks not visible on matplotlib subplots

Viewed 34

I'm trying to get ticks to show up on matplotlib subplots but nothing seems to be working.

I've tried using

ax.xaxis.set_tick_params(labelbottom = True), ax.yaxis.set_tick_params(labelleft = True, ax.minorticks_on()

and

for ax in fig.axes[:-1]:
  ax.xaxis.set_tick_params(labelbottom=True)
  ax.yaxis.set_tick_params(labelleft=True)

Here's the code I've been using:

extent = [-85, -75, 12.5, 22.5]
fig, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize = (6,6))

ax1.contourf(lon, lat, ctrl_08_26_1200_rr, levels = [1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], cmap = 'jet', norm = colors.BoundaryNorm([1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], 256), zorder = 0)
ax1.set_xticks(np.arange(-90, -72.5, 2.5))
ax1.set_yticks(np.arange(10, 27.5, 2.5))
ax1.xaxis.set_minor_locator(ticker.FixedLocator(np.arange(-90, -72.5, 2.5)))
ax1.yaxis.set_minor_locator(ticker.FixedLocator(np.arange(10,  27.5, 2.5)))
ax1.set_title('CTRL', fontname = "Arial", fontsize = 12, pad = 4.0, loc = 'right')
ax1.set_xticklabels(['90W', '87.5W', '85W', '82.5', '80W', '77.5', '75W'], fontname = "Arial", fontsize = 12) # 12
ax1.set_yticklabels(['10N', '12.5N', '15N', '17.5N','20N', '22.5N', '25N'], fontname = "Arial", fontsize = 12)# 12 is og
ax1.tick_params('both', direction='out', labelsize=10.0)
ax1.grid(visible = True, color='k', linestyle='--', linewidth=0.25)
ax1.axis(extent)
ax1.minorticks_on()
#ax1.xaxis.set_tick_params(labelbottom=False)
ax1.yaxis.set_tick_params(labelleft=True)
m  = Basemap(projection='cyl', llcrnrlat=extent[2], llcrnrlon=extent[0], urcrnrlat=extent[3], urcrnrlon=extent[1], resolution='i', ax=ax1)
#m.fillcontinents(color = 'gray')
m.drawcoastlines(linewidth=0.75, color='k')
#plt.tight_layout()

ax2.contourf(lon, lat, lin_08_26_1200_rr, levels = [1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], cmap = 'jet', norm = colors.BoundaryNorm([1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], 256), zorder = 0)
ax2.set_xticks(np.arange(-90, -72.5, 2.5))
ax2.set_yticks(np.arange(10, 27.5, 2.5))
ax2.xaxis.set_minor_locator(ticker.FixedLocator(np.arange(-90, -72.5, 2.5)))
ax2.yaxis.set_minor_locator(ticker.FixedLocator(np.arange(10,  27.5, 2.5)))
ax2.set_title('Lin', fontname = "Arial", fontsize = 12, pad = 4.0, loc = 'right')
ax2.set_xticklabels(['90W', '87.5W', '85W', '82.5', '80W', '77.5', '75W'], fontname = "Arial", fontsize = 12) # 12
ax2.set_yticklabels(['10N', '12.5N', '15N', '17.5','20N', '22.5N', '25N'], fontname = "Arial", fontsize = 12)# 12 is og
ax2.tick_params('both', direction='out', labelsize=10.0, pad = 5)
ax2.grid(b = True, color='k', linestyle='--', linewidth=0.25)
ax2.axis(extent)
ax2.minorticks_on()
#ax1.xaxis.set_tick_params(labelbottom=False)
#ax1.yaxis.set_tick_params(labelleft=True)
m  = Basemap(projection='cyl', llcrnrlat=extent[2], llcrnrlon=extent[0], urcrnrlat=extent[3], urcrnrlon=extent[1], resolution='i', ax=ax2)
#m.fillcontinents(color = 'gray')
m.drawcoastlines(linewidth=0.75, color='k')
plt.tight_layout()

ax3.contourf(lon, lat, myj_08_26_1200_rr, levels = [1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], cmap = 'jet', norm = colors.BoundaryNorm([1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], 256), zorder = 0)
ax3.set_xticks(np.arange(-90, -72.5, 2.5))
ax3.set_yticks(np.arange(10, 27.5, 2.5))
ax3.xaxis.set_minor_locator(ticker.FixedLocator(np.arange(-90, -72.5, 2.5)))
ax3.yaxis.set_minor_locator(ticker.FixedLocator(np.arange(10,  27.5, 2.5)))
ax3.set_title('MYJ', fontname = "Arial", fontsize = 12, pad = 4.0, loc = 'right')
ax3.set_xticklabels(['90W', '87.5W', '85W', '82.5', '80W', '77.5', '75W'], fontname = "Arial", fontsize = 12) # 12
ax3.set_yticklabels(['10N', '12.5N', '15N', '17.5','20N', '22.5N', '25N'], fontname = "Arial", fontsize = 12)# 12 is og
ax3.tick_params('both', direction='out', labelsize=10.0, pad = 5, labelbottom = True)
ax3.grid(b = True, color='k', linestyle='--', linewidth=0.25)
ax3.axis(extent)
ax3.minorticks_on()
#ax1.xaxis.set_tick_params(labelbottom=False)
#ax1.yaxis.set_tick_params(labelleft=True)
m  = Basemap(projection='cyl', llcrnrlat=extent[2], llcrnrlon=extent[0], urcrnrlat=extent[3], urcrnrlon=extent[1], resolution='i', ax=ax3)
#m.fillcontinents(color = 'gray')
m.drawcoastlines(linewidth=0.75, color='k')
plt.tight_layout()


ax4.contourf(imerg_lon, imerg_lat, imerg_rr.T, levels = [1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], cmap = 'jet', norm = colors.BoundaryNorm([1, 2, 4, 6, 10, 15, 20, 30, 40, 50, 75], 256), zorder = 0)
ax4.set_xticks(np.arange(-90, -72.5, 2.5))
ax4.set_yticks(np.arange(10, 27.5, 2.5))
ax4.xaxis.set_minor_locator(ticker.FixedLocator(np.arange(-90, -72.5, 2.5)))
ax4.yaxis.set_minor_locator(ticker.FixedLocator(np.arange(10,  27.5, 2.5)))
ax4.set_title('IMERG', fontname = "Arial", fontsize = 12, pad = 4.0, loc = 'right')
ax4.set_xticklabels(['90W', '87.5W', '85W', '82.5', '80W', '77.5', '75W'], fontname = "Arial", fontsize = 12) # 12
ax4.set_yticklabels(['10N', '12.5N', '15N', '17.5','20N', '22.5N', '25N'], fontname = "Arial", fontsize = 12)# 12 is og
ax4.tick_params('both', direction='out', labelsize=10.0, pad = 5, labelbottom = True)
ax4.grid(b = True, color='k', linestyle='--', linewidth=0.25)
ax4.axis(extent)
ax4.minorticks_on()
#ax1.xaxis.set_tick_params(labelbottom=False)
#ax1.yaxis.set_tick_params(labelleft=True)
m  = Basemap(projection='cyl', llcrnrlat=extent[2], llcrnrlon=extent[0], urcrnrlat=extent[3], urcrnrlon=extent[1], resolution='i', ax=ax4)
#m.fillcontinents(color = 'gray')
m.drawcoastlines(linewidth=0.75, color='k')
plt.tight_layout()

for ax in fig.axes[:-1]:
  ax.xaxis.set_tick_params(labelbottom=True)
  ax.yaxis.set_tick_params(labelleft=True)
  
for ax in fig.axes[:-1]:
  ax.tick_params(which = 'both', bottom = True, top = False, labelbottom = True)

plt.show()

And here's the image the plot generates without ticks marks:

enter image description here

Any help is greatly appreciated.

0 Answers
Related