Python-柱状图

使用python绘制柱状图:

import numpy as np
import matplotlib.pyplot as plt
# 中文和负号的正常显示
plt.rcParams[ 'font.sans-serif'] = [ 'Microsoft YaHei']
plt.rcParams[ 'axes.unicode_minus'] = False


# 用来给柱状图上面加数值;
def autolabel(rects):             
    for rect in rects:
        height = rect.get_height()
        plt.text(rect.get_x()+rect.get_width()/2.-0.2, 1.03*height, '%s' % float(height))

amounts = [len(sim80), len(sim85), len(sim90), len(sim95), len(sim100)]
levels = [str("0.80-0.85"), str("0.85-0.90"),  str("0.90-0.95"), str("0.95-1.00"), str("1.00")]
name_list = levels
num_list = amounts
plt.style.use("ggplot")
a = plt.bar(range(len(num_list)), num_list, color='rgb', tick_label=name_list)
autolabel(a)
plt.xlabel("相似度")
plt.ylabel("数量")
plt.title("Distribution above 0.80")
plt.show()

结果图:

参考:

https://blog.csdn.net/qq_29721419/article/details/71638912

https://blog.csdn.net/weixin_40198632/article/details/78858663?utm_source=blogxgwz1

猜你喜欢

转载自blog.csdn.net/weixin_41765699/article/details/83147703
今日推荐