【问题标题】:Histogram show values of vertical lines in legends直方图显示图例中垂直线的值
【发布时间】:2018-07-30 09:14:39
【问题描述】:

我可以在图例中显示垂直线(虚线)的值或在某处进行注释吗?

这是虚线的代码

plt.hist(df['wt_avg_delay'], bins=50, color='lightblue', edgecolor='black')
plt.axvline(df['wt_avg_delay'].mean(), color='orange', linestyle='dashed', linewidth=1)
plt.axvline(-19, color='green', linestyle='dashed', linewidth=1)
plt.axvline(27 color='red', linestyle='dashed', linewidth=1)

【问题讨论】:

标签: python matplotlib plot histogram


【解决方案1】:

最简单的注释方法可能是使用plt.text()

plt.text(x, y, 'annotation')

或者,您可以在行中添加标签:

import matplotlib.pyplot as plt

x = [1, 1, 1, 2, 2, 3]
p = 2.5


plt.hist(x, label='data')
plt.axvline(p, color='g', label=str(p))
plt.legend()
plt.show()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 2023-03-20
    • 2012-02-09
    • 2012-10-30
    • 2015-07-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多