title: Datetime Stacked Bar Chart with Matplotlib from dataframe
body: <p><strong>Background:</strong></p>
  
  <p>I am stuck. Or just having a blonde moment. I'm like a deer looking at headlights.</p>
  
  <p>I've queried the following dataframe from MySQL table.</p>
  
  <pre><code>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
  </code></pre>
  
  <p>I have no idea how to make it a stacked bar chart with matplotlib.</p>
  
  <p><strong>Research:</strong></p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/58330786/grouped-bar-chart-with-customized-datetime-index-using-pandas-and-matplotlib">Grouped Bar-Chart with customized DateTime Index using pandas and Matplotlib</a></li>
  <li><a href="https://stackoverflow.com/questions/44309507/stacked-bar-plot-using-matplotlib">Stacked bar plot using Matplotlib</a></li>
  </ol>
  
  <p><strong>Question:</strong></p>
  
  <p>How can I generate a stack-bar-chart with matplot lib with the above sample data?</p>
  
  <p><strong>Code snippet:</strong></p>
  
  <pre><code>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)
  </code></pre>