'Removing axis labels matplotlib
I have this image and I don't know how to remove the axis labels from the top and right hand side.
I have tried:
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
and
ax.yaxis.set_label_position("left")
ax.xaxis.set_label_position("bottom")
and
plt.tick_params(axis='both', left='off', top='off', right='off', bottom='off', labelleft='off', labeltop='off', labelright='off', labelbottom='off')
This is my code for plotting:
ax = plt.axes(projection=ccrs.PlateCarree())
plt.pcolormesh(reflon, reflat, par_interp, vmin=0, vmax=2, cmap=plt.cm.jet,
transform=ccrs.PlateCarree())
plt.colorbar()
rowskip = 50
colskip = 50
plt.quiver(reflon[0::rowskip,0::colskip],reflat[0::rowskip,0::colskip],
u[0::rowskip,0::colskip],v[0::rowskip,0::colskip],
color='black',pivot='middle', alpha=0.7, width=0.015, units='inches',
transform=ccrs.PlateCarree())
ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True,
linewidth=0.5, color='gray', alpha=0.5, linestyle='--')
ax.coastlines()
figtitle = siteid+': HS (m MSL) and Wnd: '+dstr
ax.set_title(figtitle)
dtlabel = datetime.date.strftime(dt,'%Y%m%d%H%M%S')
dtlabel = dtlabel[0:8]+'_'+dtlabel[8:14]
filenm = dtlabel+'.png'
plt.show()
plt.savefig(filenm,dpi=150,bbox_inches='tight',pad_inches=0.5)
Also, if you know how to make it so the east coast of the US is not red, let me know. Trying to figure that out too. Might be an issue with the data I am plotting though.
Solution 1:[1]
Found answer here https://scitools.org.uk/cartopy/docs/v0.13/matplotlib/gridliner.html
gl.xlabels_top = False
gl.ylabels_right = False
Solution 2:[2]
According to this, you could simply color the labels white
by
plt.xticks(color='w')
and plt.yticks(color='w')
with plt
= matplotlib.pyplot
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | DarkTrick |