Plot multiple columns of pandas DataFrame on the bar chart

Tested in python 3.11, pandas 1.5.1, matplotlib 3.6.2 Sample Data and Imports import pandas as pd import matplotlib.pyplot as plt import numpy as np np.random.seed(2022) # creates a consistent sample y = np.random.rand(10,4) y[:,0]= np.arange(10) df = pd.DataFrame(y, columns=[“X”, “A”, “B”, “C”]) X A B C 0 0.0 0.499058 0.113384 0.049974 1 1.0 0.486988 0.897657 … Read more

How to annotate each segment of a stacked bar chart

Imports and DataFrame import pandas as pd import matplotlib.pyplot as plt data = {‘var’: [‘TR’, ‘AC’, ‘F&B’], ‘2019 1Q’: [6600, 1256, 588], ‘2019 2Q’: [6566, 1309, 586], ‘2019 3Q’: [7383, 1525, 673]} df = pd.DataFrame(data) df.set_index(‘var’, inplace=True) # display(df) 2019 1Q 2019 2Q 2019 3Q var TR 6600 6566 7383 AC 1256 1309 1525 F&B … Read more