title: How to plot 3D bar chart in Matplotlib with datetime
body: <p>So I have a CSV with dataframe which looks like <a href="https://imgur.com/6WUDsZz" rel="nofollow noreferrer">this</a></p>
  <p>Here is the CSV <a href="https://userscloud.com/x3baw7f7e8de" rel="nofollow noreferrer">file</a></p>
  <p>Time Start is when the person entered the room, Time end is when the person left.
  The Duration for how many minutes they stayed in the Room is given in Duration(min) whereas the Room is in room column. The person is named in person column.</p>
  <p>I want to create a 3D Chart as shown in the <a href="https://imgur.com/pmDziIP" rel="nofollow noreferrer">image</a>.
  Which plots according to how many time duration a person stayed in which room. Like suppose on 1:00 person 'A' entered the room S2 and he left on 3:00 so the 3D chart will have a bar from that timeline.</p>
  <p>Till Now, What I tried is create a new dataframe with the start and end times merged uniquely and trying to plot it on Y axis. But it's now working.</p>
  <p>I am new to matplotlib, I would appreciate if someone could help me on how to create this chart</p>
  <p>Here is my code:</p>
  <pre><code>from mpl_toolkits.mplot3d import Axes3D
  from datetime import datetime
  import matplotlib.pyplot as plt
  import numpy as np
  import pandas
  import os
   
  df = pandas.read_csv(&quot;table1_short.csv&quot;)
   
  timeline = []
  for i in range(0, len(df)):
      curr = df.iloc[i]
      start_t, end_t = (curr['Time Start'], curr['Time End'])
      start_obj = datetime.strptime(start_t[:start_t.index(&quot;.&quot;)], '%Y-%m-%d %H:%M:%S')
      end_obj   = datetime.strptime(end_t[:end_t.index(&quot;.&quot;)], '%Y-%m-%d %H:%M:%S')
      
      timeline.append(start_obj)
      timeline.append(end_obj)
      
      
  new_df = pandas.DataFrame()
  new_df['date obj'] = list(tuple(timeline))
   
   
  x =  df['Person'] # x coordinates of each bar
  y =  new_df['date obj'] # y coordinates of each bar
  z =  df['Room']  # z coordinates of each bar
  dx = [0.5 for item in list(range(0, len(df)))]  # Width of each bar
  dy = [0.5 for item in list(range(0, len(df)))]  # Depth of each bar
  dz = df['Duration(min)']        # Height of each bar
   
  fig2 = plt.figure()
  ax12 = fig2.add_subplot(111, projection='3d')
   
  ax12.bar3d(x, y, z, dx, dy, dz, color='b', zsort='average')
  plt.show()
  </code></pre>