水平柱状图

水平柱状图模板

import matplotlib.pyplot as plt
import numpy as np

x_data = ['2011','2012','2013','2014','2015','2016','2017']
y_data = [58000,60200,63000,71000,84000,90500,107000]
bar_width = 0.3
plt.barh(y=range(len(x_data)),
        width=y_data,
        label='Java基础教程',
        # 颜色名要写对
        color='steelblue',
        alpha=0.8,
        height=bar_width,
        )
for y,x in enumerate(y_data):
    plt.text(x+5000, y-bar_width/2, '%s'%x, ha='center', va='bottom')
plt.yticks(np.arange(len(x_data)) + bar_width/2, x_data)
plt.title("kkk")
# plt.legend()
plt.show()

参考:https://blog.csdn.net/fei347795790/article/details/94331023

posted on 2021-04-07 10:57  吃我一枪  阅读(84)  评论(0编辑  收藏  举报

导航