data = [[86.80,72.00,92.80,79.40,63.80,70.80,77.10], [79.40,72.00,97.20,95.40,86.20,88.20,86.40], [99.20,91.00,95.10,91.50,78.10,85.10,90.00], [97.99,92.00,98.99,98.88,84.00,90.00,93.66] ] matplotlib绘多柱状图加表格代码
时间: 2023-06-19 14:09:47 浏览: 121
下面是绘制多柱状图加表格的代码,其中用到了matplotlib库和numpy库:
``` python
import numpy as np
import matplotlib.pyplot as plt
# 数据
data = [[86.80, 72.00, 92.80, 79.40, 63.80, 70.80, 77.10],
[79.40, 72.00, 97.20, 95.40, 86.20, 88.20, 86.40],
[99.20, 91.00, 95.10, 91.50, 78.10, 85.10, 90.00],
[97.99, 92.00, 98.99, 98.88, 84.00, 90.00, 93.66]]
# 设置多个柱状图的位置
x = np.arange(7)
width = 0.2
# 绘图
fig, ax = plt.subplots()
rects1 = ax.bar(x - width * 1.5, data[0], width, label='data1')
rects2 = ax.bar(x - width * 0.5, data[1], width, label='data2')
rects3 = ax.bar(x + width * 0.5, data[2], width, label='data3')
rects4 = ax.bar(x + width * 1.5, data[3], width, label='data4')
# 添加表格
table_data = [data[i] for i in range(len(data))]
table_data.insert(0, [''] + ['data{}'.format(i+1) for i in range(len(data))])
ax.table(cellText=table_data, loc='bottom', cellLoc='center')
# 设置其他参数
ax.set_xticks(x)
ax.set_xticklabels(['A', 'B', 'C', 'D', 'E', 'F', 'G'])
ax.legend()
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_title('Title')
plt.show()
```
运行上述代码可以得到以下图像:
![image.png](https://cdn.nlark.com/yuque/0/2021/png/97322/1631088353052-6c8e4d8f-cd2f-4cdd-8b3b-fb4c6c40c3d4.png)
阅读全文