Show tick labels when sharing an axis in matplotlib

后端 未结 3 1754
醉话见心
醉话见心 2020-12-05 10:50

I\'m running the following function:

def plot_variance_analysis(indices, stat_frames, legend_labels, shape):
    x = np.linspace(1, 5, 500)
    fig, axes = p         


        
3条回答
  •  时光取名叫无心
    2020-12-05 11:29

    The ticks that are missing have had their visible property set to False. This is pointed out in the documentation for plt.subplot. The simplest way to fix this is probably to do:

    for ax in axes.flatten():
        for tk in ax.get_yticklabels():
            tk.set_visible(True)
        for tk in ax.get_xticklabels():
            tk.set_visible(True)
    

    Here I've looped over all axes, which you don't necessarily need to do, but the code is simpler this way. You could also do this with list comprehensions in an ugly one liner if you like:

    [([tk.set_visible(True) for tk in ax.get_yticklabels()], [tk.set_visible(True) for tk in ax.get_yticklabels()]) for ax in axes.flatten()]
    

提交回复
热议问题