Python matplotlib 柱状图 添加平均线

直接上代码

主要是在代码中添加

ax.hlines(33,-1,7,linestyles='--',colors='#4472C4',label='平均值')
import matplotlib.pyplot as plt
import numpy as np

men_means = (20, 35, 30, 35, 27)
women_means = (25, 32, 34, 20, 25)
women_means2= (28, 25, 30, 40, 22)

ind = np.arange(len(men_means))  # the x locations for the groups
width = 0.2  # the width of the bars

fig, ax = plt.subplots()
rects1 = ax.bar(ind - width / 2, men_means, width,
                color='#4472C4', label='男生')

rects2 = ax.bar(ind + 0.1+width/2, women_means, width,
                color='#FFFFFF', label='不男不女',edgecolor= '#ED7E32',linestyle='--')
rects3 = ax.bar(ind + 0.2+1.5*width, women_means2, width,
                color=&

你可能感兴趣的:(Python,matplotlib,python)