'pyqtgraph stacked bar graph

I have this set of data:

import pandas as pd

df = pd.DataFrame({'x': ['A', 'B', 'C', 'D'],
                   'y1': [10, 20, 10, 30],
                   'y2': [20, 25, 15, 25],
                   'y3': [5, 10, 5, 20]})
df = df.set_index('x')
   y1  y2  y3
x
A  10  20   5
B  20  25  10
C  10  15   5
D  30  25  20

I want to draw a stacked bar chart in pyqtgraph similar to this one, drawn in matplolib:

import matplotlib.pyplot as plt
import numpy as np

fig, ax = plt.subplots()
  
bottom = np.zeros(len(df))
for col in df.columns:
    ax.bar(df.index, df[col], bottom = bottom, label = col)
    bottom += df[col]

ax.legend(frameon = True)

plt.show()

enter image description here

I have checked pyqtgraph.BarGraphItem documentation but I didn't find any information regarding stacking bar.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source