import matplotlib.pyplot as plt
data['Sample'] = pd.Categorical(data['Sample'], categories=['p1', 'p2', 'p3', 'p4', 'p5'], ordered=True)
pivot_data = data.pivot(index='CellTypes', columns='Sample', values='Per')
colors = ['#00a6d0', '#00dbb0', '#ffa861', '#b000ff', '#ff0062']
fig, ax = plt.subplots(figsize=(6,4))
pivot_data.plot(kind='barh', stacked=True, color=colors, ax=ax, width=0.6)
ax.xaxis.set_tick_params(width=2)
ax.yaxis.set_tick_params(width=2)
ax.spines['right'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.xaxis.tick_top()
ax.xaxis.set_label_position('top')
for axis in ['top', 'left']:
ax.spines[axis].set_linewidth(2)
plt.title('Percentage of Cell Types across Different Patients')
plt.xlabel('Percentage of cells (%)')
plt.ylabel('Cell Types')
plt.legend(title='Patients', bbox_to_anchor=(1.05, 1), loc='upper left')
plt.tight_layout()
plt.show()