我注释掉了无效的代码部分。 1)删除绘图的框框,然后2)显示每个条形的值
fig, ax1 = plt.subplots()
n_groups = 4
pos_energy_readings = (pos_inc1/1000, pos_inc2/1000, pos_inc3/1000,
pos_inc4/1000)
x_labels = ('February','March','April','May')
y_pos = np.arange(len(x_labels))
ax2 = ax1.twinx()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
开始:从绘图中删除框框(无效)
ax2.spines['top'].set_visible(False)
ax2.spines['right'].set_visible(False)
ax1.spines['bottom'].set_visible(False)
ax1.spines['left'].set_visible(False)
END
ax1.bar(index,pos_energy_readings,bar_width, alpha=opacity,
color='g',label='energy consumption')
ax2.plot(y_pos, daylight,color='black', marker='o',
linestyle='dashed',linewidth=2, markersize=10,label='daylight hours' )
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
ax1.legend(h1+h2, l1+l2, frameon= False, bbox_to_anchor=(0., 1.02, 1.,
.102), loc=3, ncol=2, mode="expand", borderaxespad=0.)
开始:在每个栏上显示栏的值(无效)
for i, v in enumerate(pos_energy_readings):
ax1.text(v, i, " " + str(v), color='black', va='center',
fontweight='bold')
END
ax1.set_ylabel('Energy consumption (MWh)')
ax2.set_ylabel('Daylight (hrs)')
plt.xticks(index, ('Feb','Mar','Apr','May'))`