对于您要完成的任务,我还不太清楚,但是这可能是您要完成的一种方法:
import matplotlib.pyplot as pltdaysofweek = {1:('Sunday','r'), 2:('Monday','g'), 3:('Tuesday','b'), 4:('Wednesday','yellow'), 5:('Thursday','k'), 6:('Friday', 'magenta'), 7:('Saturday', 'orange')}ax1 = plt.subplot(111)xval = [2., 4., 7.]yval = [2.5, 3.6, 2.7]for j in range(len(xval)): ax1.bar(xval[j], yval[j], width=0.8, bottom=0.0, align='center', color=daysofweek[xval[j]][1], alpha=0.6, label=daysofweek[xval[j]][0])ax1.set_xticks(xval)ax1.set_xticklabels([daysofweek[i][0] for i in xval])ax1.legend()plt.show()
结果是:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)