以前我设法创建了以下情节
import pandas as pd
import matplotlib.pyplot as plt
df_prog = pd.DataFrame({"Prognos tim": [2, 3, 3]})
df_prog.index = pd.date_range(start='2020-01-01 00', end='2020-01-01 02', freq='H')
df_prog.index = df_prog.index + pd.Timedelta(minutes=30)
现在我试图再次创建这个情节但没有成功。我的记忆力衰退了
我试过了
ax = df_prog.plot(kind='bar')
df_prog.plot(kind='line')
如中所述在同一张图表上将 Pandas DataFrame 绘制为条形图和折线图 https://stackoverflow.com/questions/23482201/plot-pandas-dataframe-as-bar-and-line-on-the-same-one-chart
但根据首先选择的是条形还是线形,仅显示一个,而不是在同一图中显示两者。
您需要将时间轴转换为字符串。然后你可以将它们绘制在一起。
import pandas as pd
import matplotlib.pyplot as plt
df_prog = pd.DataFrame({"Prognos tim": [2, 3, 3]})
df_prog.index = pd.date_range(start='2020-01-01 00', end='2020-01-01 02', freq='H')
df_prog.index = df_prog.index + pd.Timedelta(minutes=30)
_, ax = plt.subplots()
df_prog.index = df_prog.index.astype(str)
df_prog.plot(kind='line', linestyle='-', marker='o', color='r', ax=ax)
df_prog.plot(kind='bar', ax=ax)
plt.show()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)