Python 将两个熊猫系列一起绘制,其中一个显示为平面

Python 将两个熊猫系列一起绘制,其中一个显示为平面,python,pandas,matplotlib,Python,Pandas,Matplotlib,我正在练习Python函数,并试图将从同一数据帧中提取的两个系列的内容绘制到一个绘图中 当我分别绘制这两个系列时,结果是正确的。但是,当我将它们一起绘制时,我作为第二个绘制的图形在图片中显示为平面 这是我的密码: # dailyFlow and smooth are created in the same way from the same dataframe dailyFlow = pd.Series(dataFrame... smooth = pd.Series(dataFrame...

我正在练习Python函数,并试图将从同一数据帧中提取的两个系列的内容绘制到一个绘图中

当我分别绘制这两个系列时,结果是正确的。但是,当我将它们一起绘制时,我作为第二个绘制的图形在图片中显示为平面

这是我的密码:

# dailyFlow and smooth are created in the same way from the same dataframe
dailyFlow = pd.Series(dataFrame...
smooth = pd.Series(dataFrame...

# lower the noise in the signal with standard deviation = 6
smooth = smooth.resample('D').sum().rolling(31, center=True, win_type='gaussian').sum(std=6)

dailyFlow.plot(style ='-b')
plt.legend(loc = 'upper right')
plt.show()
    
smooth.plot(style ='-r')
plt.legend(loc = 'upper right')
plt.show()
    
plt.figure(figsize=(12,5))
smooth.plot(style ='-r')
dailyFlow.plot(style ='-b')
plt.legend(loc = 'upper right')
plt.show()
以下是我的函数的输出:

我已经尝试在第二个绘图中使用参数
secondary_y=True
,但随后我丢失了图例第二行的信息,并且两个绘图之间的缩放错误

互联网上的许多消息来源似乎都认为,像我这样策划这两个系列应该是正确的,但为什么第三个情节是错误的呢


非常感谢您的帮助。

对于您拥有的数据,第三个绘图是正确的。查看两个图上y轴的比例:一个上升到70000,另一个上升到60000000


我怀疑你真正想要的是一个
.rolling(…).mean()
,它应该有一个与原始数据相当的范围。

对于你拥有的数据,第三个图是正确的。查看两个图上y轴的比例:一个上升到70000,另一个上升到60000000


我怀疑你真正想要的是一个
.rolling(…).mean()
,它应该有一个与原始数据相当的范围。

如果你想让两个图都变大,你可以尝试这样的方法

fig, ax1 = plt.subplots()

ax1.set_ylim([0, 75000])
# plot first graph 

ax2 = ax1.twinx()  # second axes that shares the same x-axis
ax2.set_ylim([0, 60000000])
#plot the second graph

如果你想把这两个图都放大,你可以试试这样的

fig, ax1 = plt.subplots()

ax1.set_ylim([0, 75000])
# plot first graph 

ax2 = ax1.twinx()  # second axes that shares the same x-axis
ax2.set_ylim([0, 60000000])
#plot the second graph