How about using seaborn:
import seaborn as sns
colors = df.groupby(['1','2']).ngroup().astype('category')
sns.barplot(x=df['position'], y=1, hue=colors, dodge=False)
Output:
Or you can manually plot the bars, which allows proper scaling of position
:
cmap = {
('x','o'): 'b',
('o','x'): 'r',
('o','o'): 'g',
('x','x'): 'm'
}
fig, ax = plt.subplots()
for _, row in df.iterrows():
ax.bar(row['position'], 1, edgecolor=cmap[(row['1'], row[2])],
facecolor=(0,0,0,0),
width=10)
Output:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…