【发布时间】:2020-06-21 20:04:29
【问题描述】:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# create dataframes df0 and df1:
index0 = pd.date_range(start='2014-06-01 00:00:00', end='2014-06-01 00:15:00', freq='1S')
data0 = np.random.rand(len(index0))
df0 = pd.DataFrame(data=data0, index=index0, columns=['DF0'])
index1 = pd.date_range(start='2014-06-01 00:00:00', end='2014-06-01 00:15:00', freq='15S')
data1 = np.random.rand(len(index1))
df1 = pd.DataFrame(data=data1, index=index1, columns=['DF1'])
# plot df0 and df1:
fig,ax1 = plt.subplots(figsize=(40,10))
ax2 = ax1.twinx()
df0.plot.line( color="r", ax = ax1)
df1.plot.bar( color ='b', linewidth = 5, ax = ax2, alpha = 0.7)
plt.show()
我可以将数据框叠加为两个线图或两个条形图。但是无论我多么努力,我都无法用条形图或相反的方式覆盖线图?使用上面的代码,我只能得到 df1 的条形图,但看不到 df0 的线形图。我有什么不同的做法?
【问题讨论】:
标签: python-3.x pandas time-series bar-chart overlay