title: How to order dataframe for plotting 3d bar in pandas
body: <p>I am trying to create a chart with multiple bars in 3d from pandas. Reviewing some examples on the web, I see that the best way to accomplish this is to get a dataframe like this:</p>
  
  <pre><code>data
  
  Variable         A         B          C          D
  date
  2000-01-03  0.469112  -1.135632   0.119209   -2.104569
  2000-01-04 -0.282863   1.212112  -1.044236   -0.494929
  2000-01-05 -1.509059  -0.173215  -0.861849    1.071804
  </code></pre>
  
  <p>My dataframe is:</p>
  
  <pre><code>df
  
         Date_inicio             Date_Fin             Date_Max       Clase
  0   2004-04-09 23:00:00  2004-04-10 04:00:00  2004-04-10 02:00:00  MBCCM
  1   2004-04-12 23:00:00  2004-04-13 04:00:00  2004-04-13 00:00:00  MBSCL
  2   2004-04-24 04:00:00  2004-04-24 12:00:00  2004-04-24 09:00:00    SCL
  3   2004-05-02 07:00:00  2004-05-02 14:00:00  2004-05-02 11:00:00    SCL
  4   2004-05-30 05:00:00  2004-05-30 08:00:00  2004-05-30 07:00:00  MBCCM
  5   2004-05-31 03:00:00  2004-05-31 07:00:00  2004-05-31 05:00:00  MBCCM   
  6   2004-06-08 00:00:00  2004-06-08 05:00:00  2004-06-08 03:00:00  MBSCL
  7   2004-06-12 22:00:00  2004-06-13 12:00:00  2004-06-13 06:00:00    CCM
  8   2004-06-13 03:00:00  2004-06-13 08:00:00  2004-06-13 06:00:00  MBCCM
  9   2004-06-14 00:00:00  2004-06-14 03:00:00  2004-06-14 02:00:00  MBSCL
  10  2004-06-14 03:00:00  2004-06-14 09:00:00  2004-06-14 07:00:00  MBSCL
  11  2004-06-17 08:00:00  2004-06-17 14:00:00  2004-06-17 11:00:00  MBCCM
  12  2004-06-17 12:00:00  2004-06-17 17:00:00  2004-06-17 14:00:00  MBCCM
  13  2004-06-22 00:00:00  2004-06-22 08:00:00  2004-06-22 06:00:00    SCL
  14  2004-06-22 08:00:00  2004-06-22 14:00:00  2004-06-22 11:00:00  MBCCM 
  15  2004-06-22 23:00:00  2004-06-23 09:00:00  2004-06-23 06:00:00    CCM
  16  2004-07-01 05:00:00  2004-07-01 09:00:00  2004-07-01 06:00:00  MBCCM
  17  2004-07-02 00:00:00  2004-07-02 04:00:00  2004-07-02 02:00:00  MBSCL
  18  2004-07-04 12:00:00  2004-07-04 15:00:00  2004-07-04 13:00:00  MBCCM
  19  2004-07-06 04:00:00  2004-07-06 13:00:00  2004-07-06 07:00:00    SCL
  20  2004-07-07 04:00:00  2004-07-07 12:00:00  2004-07-07 10:00:00    CCM
  21  2004-07-08 03:00:00  2004-07-08 06:00:00  2004-07-08 05:00:00  MBCCM
  22  2004-07-08 12:00:00  2004-07-08 17:00:00  2004-07-08 13:00:00  MBCCM
  23  2004-07-08 02:00:00  2004-07-08 06:00:00  2004-07-08 04:00:00  MBCCM
  24  2004-07-09 05:00:00  2004-07-09 12:00:00  2004-07-09 08:00:00    CCM
  25  2004-07-11 18:00:00  2004-07-12 12:00:00  2004-07-11 21:00:00  MBSCL
  26  2004-07-11 23:00:00  2004-07-12 05:00:00  2004-07-12 02:00:00  MBSCL
  27  2004-07-15 11:00:00  2004-07-15 19:00:00  2004-07-15 12:00:00    CCM
  28  2004-07-16 12:00:00  2004-07-16 16:00:00  2004-07-16 14:00:00  MBCCM
  29  2004-07-17 02:00:00  2004-07-17 06:00:00  2004-07-17 05:00:00  MBCCM
  </code></pre>
  
  <p>Now I want to get the occurrence of all classes for hour. For example, how many times different classes occur at some time in Date_inicio, Date_fin and Date_max. From df i obtain the next frecuencies table, </p>
  
  <pre><code>frec
  
         Frec_Inicio  Frec_Max  Frec_Fin
  Horas                           
  1           2             0    1
  2           3             8    1
  3           5             3    2
  4           6             2    6
  5           6             6    5
  6           5             6    4
  7           5             7    2
  8           2             4    5
  9           1             6    6 
  10          0             3    2
  11          2             5    5
  12          4             1    9
  13          2             4    2
  14          3             2    4
  15          0             2    3
  16          1             1    3
  17          0             2    3 
  18          1             1    1
  19          0             0    3
  20          1             1    1
  21          1             1    0
  22          3             1    0
  23          9             1    0
  24          8             3    2
  </code></pre>
  
  <p>Now, my goal is to plot a 3D bar like the figure below</p>
  
  <p><img src="https://i.stack.imgur.com/YTeBC.png" alt="enter image description here"></p>
  
  <p>To achieve this, i write the following code</p>
  
  <pre><code>fig = plt.figure()
  ax = fig.add_subplot(111, projection='3d')
  xpos=np.arange(frec.shape[0])
  ypos=np.arange(frec.shape[1])
  xpos, ypos = np.meshgrid(xpos+0.25, ypos+0.25)
  xpos = xpos.flatten()
  ypos = ypos.flatten()
  zpos=np.zeros(frec.shape).flatten()
  
  dx=0.5 * np.ones_like(zpos)
  dy=0.5 * np.ones_like(zpos)
  dz=frec.values.ravel()
  dz[np.isnan(dz)]=0.
  
  ax.bar3d(xpos,ypos,zpos,dx,dy,dz,color='b', alpha=0.5)
  ax.set_xticks([.5,1.5,2.5])
  ax.set_yticks([.5,1.5,2.5,3.5])
  ax.w_yaxis.set_ticklabels(frec.columns)
  ax.w_xaxis.set_ticklabels(frec.index)
  ax.set_xlabel('Time')
  ax.set_ylabel('B')
  ax.set_zlabel('Occurrence')
  plt.show() 
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/D1IZT.png" alt="enter image description here"></p>
  
  <p>How I get a better plot, similar to the previous figure?</p>