单个的可以画出来,堆积的怎么画呢
import pandas as pd
import matplotlib.pyplot as plt
data = {'index': pd.Series([1,2,3,4,5,6]),
'a': pd.Series([8000,8500,9000,10000,15000,16500]),
'b': pd.Series([6000,6500,8000,8500,9000,9500]),
'c': pd.Series([4000,4200,4500,5000,5200,5500]),
'd': pd.Series([5000,4500,7800,9000,12000,10000])}
df = pd.DataFrame(data)
plt.figure(figsize=(8,5))
plt.barh(y=df['index'], width=df['a'],label='a',color='r')
plt.barh(y=df['index'], width=df['b'],left=df['a'],label='b',color='c')
plt.barh(y=df['index'], width=-df['c'],label='c',color='b')
plt.barh(y=df['index'], width=-df['d'],left=-df['c'],label='d',color='gold')
plt.legend()
画出来是: