数据可视化之matplotlib实战:plt.barh() 绘制条形图
程序员文章站
2022-06-01 18:38:11
...
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
# 防止乱码
mpl.rcParams["font.sans-serif"] = ["SimHei"]
mpl.rcParams["axes.unicode_minus"] = False
# 生成数据
x = [1,2,3,4,5]
y = [6,10,4,5,1]
# 生成柱状图
"""
x:柱状图中柱体标签值
y:柱状图中柱体高度
align:柱体对齐方式
color:柱体颜色
tick_label:刻度标签值
alpha:柱体的透明度
"""
plt.barh(x,y,align="center",color="b",tick_label=["A","B","C","D","E"],alpha=0.6)
# 设置x,y轴标签
plt.xlabel("测试难度")
plt.ylabel("试卷份数")
# 设置网格
plt.grid(True, axis="y",ls=":",color="r",alpha=0.3)
plt.show()