matplotlib share x axis but don't show x axis tick labels for both, just one

前端 未结 5 837
清酒与你
清酒与你 2020-11-29 19:56

I\'m using python + matplotlib and I\'m having two plots share an axis. If you try to set graph1.set_xticklabels([]) while sharing an axis, it has no effect bec

5条回答
  •  醉话见心
    2020-11-29 20:41

    Unfortunately, I am not allowed to comment on esmit's answer (which is the best solution in my opinion, thanks esmit), so I have to write my comment as a new answer: I put his solution into a simple function

    def remove_inner_ticklabels(fig):
        for ax in fig.axes:
            try:
                ax.label_outer()
            except:
                pass
    

    which you can call before plt.show(). Joe Kington's answer did not work for me for some reason.

提交回复
热议问题