"""
@author:lian
"""
import matplotlib.pyplot as plt
import numpy as np
import streamlit as st
label = ['平板', '筏板', '矩形梁', '雨篷', '汽车坡道']
first = np.random.rand(5)
second = np.random.rand(5)
third = np.random.rand(5)
data = [first, second, third]
def autolabel(rects, plt_):
for rect in rects:
height = rect.get_height()
plt_.annotate(f'{height:.2f}',
xy=(rect.get_x() + rect.get_width() / 2, height),
xytext=(0, 3),
textcoords="offset points",
ha='center', va='bottom')
def create_multi_bars(datas, labels, x_label, y_label, tick_step=1, group_gap=0.2, bar_gap=0):
ticks = np.arange(len(labels)) * tick_step
group_num = len(datas)
group_width = tick_step - group_gap
bar_span = group_width / group_num
bar_width = bar_span - bar_gap
baseline_x = ticks - (group_width - bar_span) / 2
for index, y in enumerate(datas):
tmp = plt.bar(baseline_x + index * bar_span, y, bar_width)
autolabel(tmp, plt)
plt.xlabel(x_label)
plt.ylabel(y_label)
plt.xticks(ticks, labels)
return plt
if __name__ == '__main__':
a = create_multi_bars(data, label, '清单项', '精确率')
st.pyplot(a)