Background:
I am stuck. Or just having a blonde moment. I'm like a deer looking at headlights.
I've queried the following dataframe from MySQL table.
date operation
2020-05-07 A
2020-05-08 B
2020-05-08 A
2020-05-12 A
2020-05-12 A
2020-05-12 B
2020-05-13 C
2020-05-13 A
2020-05-13 B
2020-05-14 A
2020-05-19 B
2020-05-21 A
2020-05-25 A
2020-05-26 B
2020-05-26 C
2020-05-26 A
2020-05-26 A
2020-05-29 A
I have no idea how to make it a stacked bar chart with matplotlib.
Research:
- Grouped Bar-Chart with customized DateTime Index using pandas and Matplotlib
- Stacked bar plot using Matplotlib
Question:
How can I generate a stack-bar-chart with matplot lib with the above sample data?
Code snippet:
import datetime as dt
import mysql.connector
import os
import pandas as pd
# import numpy as np
import matplotlib.pyplot as plt
import datetime
def generate_monthly_graph():
query = "SELECT [...]`"
mycursor.execute(query)
mycursor.execute(query)
data = mycursor.fetchall()
df = pd.DataFrame(data, columns=['date', 'operation'])
df = df.set_index('date')
df.index = pd.to_datetime(df.index)