title: Stacked bar plots with some missing values and many indices
body: <p>I have a mass DataFrame <code>df</code> (sorted by <code>'year'</code>):</p>
  <pre><code>year       gender
  1894       male
  1895       male
  1895       male
  1896       male
  1900       male
  ...
  2008       male
  2008       female
  2009       male
  2009       female
  2009       female
  </code></pre>
  <p>and I aim to make a stacked bar chart with the x-axis <code>'year'</code> and the y-axis the number of occurrences of those year values, with <code>['gender'] == 'female'</code> on top of <code>['gender'] == 'male'</code> on each bar.</p>
  <p>I tried the following:</p>
  <pre><code>import plotly.express as px
  
  df['freq'] = df.groupby('year')['gender'].transform('count')
  
  fig = px.bar(df, x=&quot;year&quot;, y=&quot;freq&quot;, color='gender')
  fig.show()
  </code></pre>
  <p>However, this takes up too much runtime and returns a blank graph. So, instead of creating a stacked bar chart using <code>plotly</code>, I attempted utilizing <code>matplotlib</code>:</p>
  <pre><code>import matplotlib.pyplot as plt
  
  df_male = df[df['gender'] == 'male']
  df_female = df[df['gender'] == 'female']
  
  X = range(1894, 2010)
  
  plt.bar(X, df_male['year'], color = 'b')
  plt.bar(X, df_female['year'], color = 'r', bottom = df_male['year'])
  plt.show()
  </code></pre>
  <p>But this returns <code>ValueError: shape mismatch: objects cannot be broadcast to a single shape</code>, which I wonder if this is due to the fact that there are some years between 1894 and 2009 in <code>df</code> that do not exist (e.g. 1897, 1898, 1899, etc.).</p>
  <p>Any insights to help me go further would be appreciated.</p>