title: Aligned Stacked Bar Chart
body: <p>Is there a type of stacked bar chart where there are gaps in the bars in order to align each category? Alternatively is there a type of heatmap where the grid changes proportionally to the category size?</p>
  <p>Something that looks like this:
  <a href="https://i.stack.imgur.com/vzdHv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vzdHv.png" alt="" /></a></p>
  <p>Code to reproduce example:</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import plotly.express as px
  
  # Create subset data
  subset_sizes = {
      '1000': 0.0937, '0100': 0.0083, '1100': 0.0677, '0010': 0.0014, '1010': 0.0781, 
      '0110': 0.1087, '1110': 0.1667, '0001': 0.0005, '1001': 0.0875, '0101': 0.0032, 
      '1101': 0.0734, '0011': 0.002, '1011': 0.0731, '0111': 0.0519, '1111': 0.1824
  }
  
  # Turn subsets into dataframe of entries
  stacked_bar_data = []
  for subset, value in subset_coverages.items():
      for wine_i, d in enumerate(subset):
          if d == '1':
              stacked_bar_data.append((str(wine_i), subset, value))
          else:
              stacked_bar_data.append((str(wine_i), subset+'NA', value))   
  stacked_bar_df = pd.DataFrame(stacked_bar_data, columns=['group', 'category', 'value'])
  
  # Sort each group for each category so that each group appears in the same order
  stacked_bar_df = stacked_bar_df.sort_values(['category', 'group'], ascending=False)
  
  # Stacked bar chart
  fig = px.bar(stacked_bar_df, x=&quot;group&quot;, y=&quot;value&quot;, color=&quot;category&quot;, title=&quot;Aligned Stacked Bar Chart&quot;)
  fig.update_layout(barmode='stack', bargap=0)
  
  # Hide category+group pairs that aren't present
  for i in range(len(fig.data)):
      if fig.data[i]['name'][-2:] == 'NA':
          fig.data[i]['showlegend'] = False
          fig.data[i]['marker']['color'] = 'rgba(0, 0, 0, 0.0)'
  
  fig.show()
  </code></pre>