runoffとvalueにはそれぞれ13個のデータがあります。 double y軸は、2つのセットデータを毎年比較するために使用されます。しかし、赤い記号が整列していないことと、毎年青い記号の間の数字が間違っています。私は逃した任意の詳細は?
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
されるようにあなたが '' TSM''と '' runoff''の両方を与えてみました:あなたのx軸のセットアップコードは、ちょうどこの
ax2 = ax1.twinx()
移動を呼び出す前に移動します共通のx配列? '' plot(t、TSM) ''と '' plot(t、runoff) ''と同様です。 – alexblae