title: matplotlib double y axis
body: <p><a href="https://i.stack.imgur.com/Awhme.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Awhme.png" alt="the chart"></a></p>
  
  <p>runoff and value have 13 data, respectively. The double y axis are used for comparing the two sets data every year. But the figure is wrong due to unaligned red symbol and between blue symbol every year. is there any detail I missed？</p>
  
  <pre><code>runoff=[1877, 2690.9, 3632, 4525, 1512, 4459, 1614.3, 2595, 1270.2, 2308.2, 2436, 1742.8,2658.7]
  TSM=['22.805241997828', '26.649050918463', '23.875097901606', '22.60339679601', '25.898807017902', '28.610553136975', '28.489485098388', '22.206851921378', '21.958918945009', '15.629827074318', '18.894425896003', '20.511980938426', '19.879687929129']
  
  def draw(df):
  
      font = {'family' : 'Times New Roman',             
          'color'  : 'black'          ,  
          'weight' : 'normal'         ,  
          'size'   : 11 
          }
  
      fig=plt.figure(11,figsize=(4.5,3))
      ax1=plt.axes([0.10,0.24,0.78,0.73])
      ax2=ax1.twinx()
      matplotlib.rcParams["font.family"] = "Times New Roman"#全局times new roamn
      matplotlib.rcParams['xtick.direction'] = 'in'
      matplotlib.rcParams['ytick.direction'] = 'inout' 
      ax1.plot(value,label='TSM',marker='o',color='red')
      #plt.ylim([10,30])
  
  
      ax2.plot(runoff,label='Sediment runoff',marker='s',color='blue',linestyle='--')
      ax2.spines['left'].set_color('red')
      ax2.spines['right'].set_color('blue')
      ax2.tick_params(which='both',color='blue')
      ax1.tick_params(axis='y',which='both',color='red')
  
      xticks=list(range(0,len(time),2))
      xlabels=[time[index] for index in xticks]
      xticks.append(len(time)+1)
      #xlabels.append('2015')
      #xlabels.append('2016')
      ax1.set_xticks(xticks)
      ax1.set_xticklabels(xlabels,rotation=0,fontdict=font)
  
  
      ax2.spines['bottom'].set_linewidth(1.25)
      ax2.spines['left'].set_linewidth(1.25) 
      ax2.spines['right'].set_linewidth(1.25) 
      ax2.spines['top'].set_linewidth(1.25) 
  
      legend1=ax1.legend(loc=1,ncol=2)
      legend1.get_title().set_fontsize(fontsize=20)
      legend2=ax2.legend(loc=0,bbox_to_anchor=(0.6,0.85),borderaxespad=0.)
      legend2.get_title().set_fontsize(fontsize=20)
  
      f=plt.gcf()
      f.text(0.001,0.7,u'TSM $(mg/L)$',fontdict=font,color='black',rotation=90)
      f.text(0.5,0.09,u'Time (year)',fontdict=font,color='black')
      f.text(0.99,0.82,u'Sediment runoff ($ton$)',fontdict=font,color='black',rotation=90)  
      f.canvas.draw()
      plt.show()
      return True
  </code></pre>