一般来说,最好使用面向对象的方法,因为
plt.something()
当你添加坐标轴和数字时变得越来越难以预测。
df.plot(...)
默认为不一定是所需的ax。
# First figure.
fig1, ax1 = plt.subplots(figsize=(25, 10))
ax2 = ax1.twinx()
ax1.bar(daily_summary.index, daily_summary['hour_max_demand'], width=20, alpha=0.2, color='orange')
ax1.grid(b=False) # turn off grid #2
ax2.plot(daily_summary.kW)
ax2.set_title('Max Demand per Day and Max Demand Hour of Day')
ax2.set_ylabel('Electric Demand kW')
ax1.set_ylabel('Hour of Day')
fig1.savefig('./plots/Max_Demand_and_Max_Hour_of_Day.png')
# Figure 2.
fig2, ax3 = plt.subplots(figsize=(25, 10))
ax3.title(' 7 Day Rolling Average - kWh / Day')
data3 = daily_summary.kWH.rolling(7, center=True).mean()
ax3.plot(data3)
fig2.savefig('./plots/kWhRollingAvg.png')