如您所说,您可以使用熊猫来创建堆积的条形图。想要拥有“季节性地块”的论点是无关紧要的,因为每个季节性地块和每个熊猫地块最终都只是matplotlib对象,因为两个库的绘图工具都只是matplotlib包装器。
因此,这是一个完整的解决方案(从@andrew_reece的答案中获取数据创建)。
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
n = 500
mark = np.random.choice([True,False], n)
periods = np.random.choice(['BASELINE','WEEK 12', 'WEEK 24', 'WEEK 4'], n)
df = pd.DataFrame({'mark':mark,'period':periods})
ct = pd.crosstab(df.period, df.mark)
ct.plot.bar(stacked=True)
plt.legend(title='mark')
plt.show()