Python 熊猫散点图:停止轴的自动缩放

Python 熊猫散点图:停止轴的自动缩放,python,pandas,matplotlib,plot,Python,Pandas,Matplotlib,Plot,我试图创建两个具有相同轴的独立散点图。如下面的代码所示,我正在显式设置轴限制。但是,由于两个图之间的数据分布不同,因此这些限制范围内的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,

我试图创建两个具有相同轴的独立散点图。如下面的代码所示,我正在显式设置轴限制。但是,由于两个图之间的数据分布不同,因此这些限制范围内的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轴在两个图上相同)

您不能在对数轴上设置0的
xlim
。尝试将其设置为要匹配的轴低端的数字。e、 g

ax1.set_xlim([2e-3,0.4])

ax2.set_xlim([2e-3,0.4])