【发布时间】:2017-11-04 13:20:57
【问题描述】:
有人可以告诉我如何修改这个使用 matplotlib 的 Python 代码,这样无论绘制多少分数,条形的宽度都将保持不变?提前谢谢!
# data to plot
n_groups = len(math_scores)
###print "im here", math_scores,verbal_scores
scores_readingwriting = verbal_scores
scores_math = math_scores
# create plot
fig, ax = plot.subplots()
index = np.arange(n_groups)
bar_width = 0.35
opacity = 0.8
rects1 = plot.bar(index, scores_readingwriting, bar_width,
alpha=opacity,
color='black',
label='R/W')
rects2 = plot.bar(index + bar_width, scores_math, bar_width,
alpha=opacity,
color='grey',
label='Math')
plot.xlabel('Date',size='14')
plot.ylabel('Scores',size='14')
plot.title(str(first_names[i])+' '+str(last_names[i])+"'s History",size='17')
num=len(scores)
###print datesofinterest
plot.xticks(index + bar_width/2, datesofinterest,size='12')
plot.yticks(size='12')
axes = plot.gca()
axes.set_ylim([200,800])
plot.legend()
plot.tight_layout()
fig.savefig('img'+str(student_ids[i])+'.png')
【问题讨论】:
标签: python python-2.7 matplotlib