import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
test = pd.DataFrame(
{'cluster': ['1', '1', '1', '1', '2', '2', '2', '2', '2', '3', '3', '3'],
'type': ['a', 'b', 'c', 'a', 'a', 'b', 'c', 'c', 'a', 'b', 'c', 'a']})
tab = pd.crosstab(test.cluster, test.type, normalize='index', margins=True)
fig, ax = plt.subplots()
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
tab.iloc[:-1].plot(ax=ax, kind='bar', color=colors)
for y, c in zip(tab.loc['All'], colors):
ax.axhline(y=y, color=c, linestyle=':', alpha=0.5)
plt.show()