栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Matplotlib中条形图的平均折线

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Matplotlib中条形图的平均折线

如果您想用竖线表示平均使用率

axvline(x_value)
。这将放置一条垂直线,该垂直线始终跨越y轴的整个(或指定的分数)。还有
axhline
水平线。

在其他作品中,您可能会有这样的事情:

ax.axvline(data1.mean(), color='blue', linewidth=2)ax.axvline(data2.mean(), color='green', linewidth=2)

作为一个更完整但不必要的复杂示例(大多数示例都很好地用了弯曲的箭头注释了均值):

import numpy as npimport matplotlib.pyplot as pltdata1 = np.random.normal(0, 1, 1000)data2 = np.random.normal(-2, 1.5, 1000)fig, ax = plt.subplots()bins = np.linspace(-10, 5, 50)ax.hist(data1, bins=bins, color='blue', label='Dataset 1',        alpha=0.5, histtype='stepfilled')ax.hist(data2, bins=bins, color='green', label='Dataset 2',        alpha=0.5, histtype='stepfilled')ax.axvline(data1.mean(), color='blue', linewidth=2)ax.axvline(data2.mean(), color='green', linewidth=2)# Add arrows annotating the means:for dat, xoff in zip([data1, data2], [15, -15]):    x0 = dat.mean()    align = 'left' if xoff > 0 else 'right'    ax.annotate('Mean: {:0.2f}'.format(x0), xy=(x0, 1), xytext=(xoff, 15), xycoords=('data', 'axes fraction'), textcoords='offset points', horizontalalignment=align, verticalalignment='center', arrowprops=dict(arrowstyle='-|>', fc='black', shrinkA=0, shrinkB=0,      connectionstyle='angle,angleA=0,angleB=90,rad=10'), )ax.legend(loc='upper left')ax.margins(0.05)plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/668220.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号