您只需调整
ax
对象,即每个单独的绘图:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_clipboard() # copy data in the SO question
sums = df.groupby('Software').sum().T
fig, axes = plt.subplots(1, len(sums.index), sharey=True, figsize=(12, 3))
plt.subplots_adjust(wspace=0.2)
colors = ['#6caddf', '#f27077', '#9dd374', '#fab26a']
for ax, software, parameter, color in zip(axes, sums.columns, sums.index, colors):
ax.barh(sums.loc[parameter].index, sums.loc[parameter].values, color=color)
ax.set(xticks=range(0, df.drop('Software', axis=1).max().max()+1, 2000), )
ax.set_title(parameter, y=0.9)
ax.yaxis.set_tick_params(length=0)
for d in ["top", "bottom", "right", "left"]:
ax.spines[d].set_visible(False)
fig.suptitle('Summary of Softwares', y=1.05, fontweight='bold')
plt.show()