Plotting Pandas Multiindex Bar Chart

import pandas as pd data = pd.DataFrame([ (‘Q1′,’Blue’,100), (‘Q1′,’Green’,300), (‘Q2′,’Blue’,200), (‘Q2′,’Green’,350), (‘Q3′,’Blue’,300), (‘Q3′,’Green’,400), (‘Q4′,’Blue’,400), (‘Q4′,’Green’,450), ], columns=[‘quarter’, ‘company’, ‘value’] ) data = data.set_index([‘quarter’, ‘company’]).value data.unstack().plot(kind=’bar’, stacked=True) If you don’t want to stack your bar chart: data.unstack().plot(kind=’bar’)

Stacked Bar Chart with Centered Labels

The following method is more succinct, and easily scales. Putting the data into a pandas.DataFrame is the easiest way to plot a stacked bar plot. Using pandas.DataFrame.plot.bar(stacked=True), or pandas.DataFrame.plot(kind=’bar’, stacked=True), is the easiest way to plot a stacked bar plot. This method returns a matplotlib.axes.Axes or a numpy.ndarray of them. Since seaborn is just a … Read more

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)