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 plot multiple bars grouped

import matplotlib.pyplot as plt from matplotlib.dates import date2num import datetime x = [ datetime.datetime(2011, 1, 4, 0, 0), datetime.datetime(2011, 1, 5, 0, 0), datetime.datetime(2011, 1, 6, 0, 0) ] x = date2num(x) y = [4, 9, 2] z = [1, 2, 3] k = [11, 12, 13] ax = plt.subplot(111) ax.bar(x-0.2, y, width=0.2, color=”b”, align=’center’) … Read more

How to add percentages on top of grouped bars

The seaborn.catplot organizing function returns a FacetGrid, which gives you access to the fig, the ax, and its patches. If you add the labels when nothing else has been plotted you know which bar-patches came from which variables. From @LordZsolt’s answer I picked up the order argument to catplot: I like making that explicit because … Read more

How to create a grouped bar plot

Pandas will show grouped bars by columns. Entries in each row but different columns will constitute a group in the resulting plot. Hence you need to “reshape” your dataframe to have the “group” as columns. In this case you can pivot like df.pivot(“column”, “group”, “val”) producing group g1 g2 column c1 10 8 c2 12 … Read more

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