承接上一篇问题一,关于bar()函数的疑难杂症,主要是坐标的对齐方式,昨天的坐标自动居中了,今天翻阅了一些资料发现了根源所在,各种参数设置啊,先来个简单的例子吧:
import numpy as np
import matplotlib.pyplot as plt
men_means= (20, 35, 30, 35, 27)
women_means= (25, 32, 34, 20, 25)
ind = np.arange(len(men_means)) # the x locations for the groups
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(ind - width/2, men_means, width, color='SkyBlue', label='Men')
rects2 = ax.bar(ind + width/2, women_means, width,color='IndianRed', label='Women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_ylabel('Scores')
ax.set_title('Scores by group and gender')
plt.xticks(ind,('G1', 'G2', 'G3', 'G4', 'G5'))
ax.legend()
plt.show()
简单的直方图设置,先看下效果图: