我认为你可以通过在使用表格制作表格时设置边界框来解决第一个问题bbox
像这样:
bbox=[0, 0.225, 1, 0.2]
其中参数是[left, bottom, width, height]
.
对于第二个问题(着色),那是因为color
数组不对应seaborn
染色。您可以查询seaborn
调色板与
sns.color_palette(palette='colorblind')
这会给你一个颜色列表seaborn
正在使用。
检查以下修改:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
# Set styles
plt.style.use(['seaborn-paper', 'seaborn-whitegrid'])
plt.style.use(['seaborn'])
sns.set(palette='colorblind')
matplotlib.rc("font", family="Times New Roman", size=12)
labels = ['n=1','n=2','n=3','n=4','n=5']
a = [98.8,98.8,98.8,98.8,98.8]
b = [98.6,97.8,97.0,96.2,95.4]
bar_width = 0.20
data = [a,b]
colors = sns.color_palette(palette='colorblind')
columns = ('n=1', 'n=2', 'n=3', 'n=4', 'n=5')
index = np.arange(len(labels))
fig = plt.figure(figsize=(12,9))
plt.bar(index, a, bar_width)
plt.bar(index+bar_width+.02, b, bar_width)
plt.table(cellText=data,
rowLabels=[' a ', ' b '],
rowColours=colors,
colLabels=columns,
loc='bottom',
bbox=[0, 0.225, 1, 0.2])
fig.subplots_adjust(bottom=0.1)
plt.ylabel('Some y label which effect the bottom padding!')
plt.xticks([])
plt.title('Some title')
plt.show()
我还将子图调整更改为subplot_adjust(bottom=0.1)
因为否则它就不会出来。这是输出: