Matplotlib辅助y轴条形图

时间:2014-12-29 09:46:40

标签: python matplotlib

尝试绘制具有多个y轴的条形图..这是我尝试过的。 为什么我的数据集[1]和[2]; [3]和[4]重叠?

fig = plt.figure()
ax = fig.add_subplot(111)

## the data
N = len(dataset[1])
INPUT_RAPL_PAAE = dataset[1]
INPUT_RAPL_AAE = dataset[2]
REPP_RAPL_PAAE = dataset[3]
REPP_RAPL_AAE = dataset[4]

## necessary variables
ind = np.arange(N)                # the x locations for the groups
width = 0.35                      # the width of the bars

ax2 = ax.twinx()
## the bars
rects1 = ax.bar(ind, INPUT_RAPL_PAAE, width,
            color='black',
            error_kw=dict(elinewidth=2,ecolor='red'))

rects2 = ax.bar(ind+width, REPP_RAPL_PAAE, width,
                color='red',
                error_kw=dict(elinewidth=2,ecolor='black'))

rects3 = ax2.bar(ind, INPUT_RAPL_AAE, width,
            color='0.1',
            error_kw=dict(elinewidth=2,ecolor='red'))

rects4 = ax2.bar(ind+width, REPP_RAPL_AAE, width,
                color='0.5',
                error_kw=dict(elinewidth=2,ecolor='black'))

# axes and labels
ax.set_xlim(-width,len(ind)+width)
ax.set_ylim(0,100)
ax.set_ylabel('Scores')
ax2.set_ylim(0, 8000)
ax2.set_ylabel('Power (mW)')
ax.set_title('Scores by group and gender')
xTickMarks = dataset[0]
ax.set_xticks(ind+width)
xtickNames = ax.set_xticklabels(xTickMarks)
plt.setp(xtickNames, rotation=90, fontsize=10)

## add a legend
#ax.legend( (rects1[0], rects2[0]), ('Men', 'Women') )

plt.show()

次要图与第一个图重叠。 不知道我做错了什么..

0 个答案:

没有答案