【发布时间】:2019-08-21 21:30:59
【问题描述】:
我想绘制一条虚线,显示两个变量的平均值。这是我的条形图代码:
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
men_means = [2000, 3400, 3000, 3005, 2700]
women_means = [2500, 3200, 3004, 2000, 2005]
x = np.arange(len(labels)) # the label locations
width = 0.35 # the width of the bars
fig, ax = plt.subplots()
rects1 = ax.bar(x - width/2, men_means, width, label='Men')
rects2 = ax.bar(x + width/2, women_means, width, label='Women')
【问题讨论】:
-
您希望您的线路是虚线而不是全连接吗?您图片中的线条确实与每个条形的平均值相交。
-
@CeliusStingher 一条虚线,我试过
plot.axhline(np.mean(df), linestyle='--', color='blue'),但这适用于所有条形图。你能帮我吗,谢谢!!! -
不清楚你在问什么
-
我将编辑您的问题,使其格式正确
标签: python matplotlib graph