[英]How do I remove labels from one axis in a subplot?
我在 MacOS 上使用 Python 3.9。 很快,我必須制作一個帶有 4 個子圖的 plot,它們共享軸。 代碼如下所示:
#take some data
gs = gridspec.GridSpec(2, 2, height_ratios = [3, 1])
ax0 = plt.subplot(gs[0])
#plot data, make legend, etc.
ax2 = plt.subplot(gs[2], sharex = ax0)
#plot data, make legend, etc.
#take more data
ax1 = plt.subplot(gs[1], sharey = ax0)
#plot data, make legend, etc.
ax3 = plt.subplot(gs[3], sharex = ax1, sharey = ax2)
#plot data, make legend, etc.
plt.show()
如您所見,一些圖彼此共享一個軸。 問題是在 x 軸上一切都很好,而在 y 軸上卻不是(見圖)。 進入正題:如何刪除右側 plot 垂直軸上的數字而不是左側的數字? 我看過很多帖子,其中的問題是通過諸如此類的方式解決的
ax.set_yticklabels([])
但這也刪除了左邊的數字 plot。
嘗試這個:
ax1.tick_params('y', labelleft=False)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.