图3X3子图有共享的x,y轴和标签?

时间:2017-08-16 17:43:14

标签: python shared labels axes subplot

我无法使用以下代码添加带有公共轴和标签的创建3x3子图:

    fig = plt.figure(figsize=(24, 12))
    ax = fig.add_subplot(111)    # The big subplot
    fig.text(0.5, 0.04, 'Time (minutes)', ha='center')
    fig.text(0.04, 0.5, 'Distance travelled (pixels)', va='center', 
   rotation='vertical')
    # Turn off axis lines and ticks of the big subplot
     ax.spines['top'].set_color('none')
     ax.spines['bottom'].set_color('none')
     ax.spines['left'].set_color('none')
     ax.spines['right'].set_color('none')
     ax.tick_params(labelcolor='w', top='off', bottom='off', 
     left='off', right='off')

     ax1 = fig.add_subplot(331)
     ax1.errorbar(Time, MD11, MD11err, capsize=3, ls='none', 
      color='red', elinewidth=0.5, capthick=1)
      ax1.scatter(Time, S1, s=20, color = 'grey')
      ax1.plot(Time, MD11, color = 'red', label="First 1ug/g 
     injection")
      ax1.plot(Time, S1, color = 'grey', label="Saline")
      ax1.spines['right'].set_visible(False)
      ax1.spines['top'].set_visible(False)
      ax1.title ('MDMA 1 ug/g ')
      ax1.ylabel('First Injection', va='center', rotation='vertical')


       ax2 = fig.add_subplot(332)
       ax2.errorbar(Time, MD31, MD31err, capsize=5, ls='none', 
          color='red', elinewidth=1, capthick=2)
        ax2.errorbar(Time, S4, S4err, capsize=5, ls='none', 
      color='gray', elinewidth=1, capthick=2)
       ax2.scatter(Time, MD31,s=20, color = 'red') 
        ax2.scatter(Time, S4,s=20, color = 'grey')
       ax2.plot(Time, MD31, color = 'red', label="First 3ug/g 
       injection")
       ax2.plot(Time, S4, color = 'grey', label="Saline")

依此类推至ax9。上面的代码刚刚创建了331子图,而不是其他的子图。我已正确定义了所有变量。请帮忙。

0 个答案:

没有答案