2
我正嘗試用相同的軸創建兩個單獨的散點圖。如下面的代碼所示,我明確地設置了我的軸限制。但是,因爲數據的擴散在兩個圖之間不同,所以x軸在內的縮放比例正在改變。比較圖1的下方& 2,使用相同代碼(除不同的x值)繪製:大熊貓散點圖:停止軸的自動縮放
圖1
#set up figure
fig, ax1 = plt.subplots(1,1)
#plot first series (left y axis)
df.plot(ax=ax1, kind='line', x=bin1, y='hfall', logx=True,
color='DarkBlue', style='.', markersize=5, legend=False)
#set up second axis as duplicate of the first
ax2 = ax1.twinx()
#plot second series (right y axis)
df.plot(ax=ax2, kind='line', x=bin1, y='vf', logx=True,
color='Red', style='.', markersize=5, legend=False)
#set axes limits
ax1.set_xlim([0.,0.4])
ax1.set_ylim([1,1.15])
ax2.set_xlim([0.,0.4])
ax2.set_ylim([2e-06,6e-06])
#set labels and title
ax1.set_ylabel('Total horizontal flux ($kg/m^2/s$)', color='DarkBlue')
ax1.set_xlabel('horizontal flux in bin1 ($kg/m^2/s$)')
ax1.set_title('bin1', loc='center', fontsize=14)
ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax2.set_ylabel('Total vertical flux (all bins) ($kg/m^2/s$)', color='Red')
plt.show()
圖2
#set up figure
fig, ax1 = plt.subplots(1,1)
#plot first series (left y axis)
df.plot(ax=ax1, kind='line', x=bin2, y='hfall', logx=True,
color='DarkBlue', style='.', markersize=5, legend=False)
#set up second axis as duplicate of the first
ax2 = ax1.twinx()
#plot second series (right y axis)
df.plot(ax=ax2, kind='line', x=bin2, y='vf', logx=True,
color='Red', style='.', markersize=5, legend=False)
#set axes limits
ax1.set_xlim([0.,0.4])
ax1.set_ylim([1,1.15])
ax2.set_xlim([0.,0.4])
ax2.set_ylim([2e-06,6e-06])
#set labels and title
ax1.set_ylabel('Total horizontal flux ($kg/m^2/s$)', color='DarkBlue')
ax1.set_xlabel('horizontal flux in bin2 ($kg/m^2/s$)')
ax1.set_title('bin2', loc='center', fontsize=14)
ax2.ticklabel_format(axis='y', style='sci', scilimits=(0,0))
ax2.set_ylabel('Total vertical flux (all bins) ($kg/m^2/s$)', color='Red')
plt.show()
我理解這可能是發生在最好的顯示我的數據中的變化,但我想該地塊直接比較 - 佔領對數尺度空間的轉變是需要了解的。所以,有沒有人知道我可以如何阻止x軸自動縮放發生? (即,我希望x軸在兩個圖上相同)