title: Grouped Bar Plot with Pattern Fill using Python and Matplotlib
body: <p>I found the following barplot on the following website: <a href="http://ndaratha.blogspot.com/2015/03/grouped-bar-plot" rel="nofollow noreferrer">http://ndaratha.blogspot.com/2015/03/grouped-bar-plot</a><a href="https://i.stack.imgur.com/zmO7Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zmO7Y.png" alt="enter image description here"></a></p>
  
  <p>According to the website, it corresponds to the following code </p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  # Input data; groupwise
  green_data = [16, 23, 22, 21, 13, 11, 18, 15]
  blue_data =  [ 3,  3,  0,  0,  5,  5,  3,  3]
  red_data =   [ 6,  6,  6,  0,  0,  0,  0,  0]
  black_data = [25, 32, 28, 21, 18, 16, 21, 18]
  
  labels = ['XI', 'XII', 'XIII', 'XIV', 'XV', 'XVI', 'XVII', 'XVIII']
  
  # Setting the positions and width for the bars
  pos = list(range(len(green_data))) 
  width = 0.15 # the width of a bar
  
  # Plotting the bars
  fig, ax = plt.subplots(figsize=(10,6))
  
  bar1=plt.bar(pos, green_data, width,
                   alpha=0.5,
                   color='w',
                   hatch='x', # this one defines the fill pattern
                   label=labels[0])
  
  plt.bar([p + width for p in pos], blue_data, width,
                   alpha=0.5,
                   color='w',
                   hatch='o',
                   label=labels[1])
  
  plt.bar([p + width*2 for p in pos], red_data, width,
                   alpha=0.5,
                   color='k',
                   hatch='',
                   label=labels[2])
  
  plt.bar([p + width*3 for p in pos], black_data, width,
                   alpha=0.5,
                   color='w',hatch='*',
                   label=labels[3])
  
  
  # Setting axis labels and ticks
  ax.set_ylabel('Number of Switching')
  ax.set_xlabel('Strategy')
  ax.set_title('Grouped bar plot')
  ax.set_xticks([p + 1.5 * width for p in pos])
  ax.set_xticklabels(labels)
  
  # Setting the x-axis and y-axis limits
  plt.xlim(min(pos)-width, max(pos)+width*5)
  plt.ylim([0, max(green_data + blue_data + red_data) * 1.5])
  
  # Adding the legend and showing the plot
  plt.legend(['OLTC', 'SVC', 'SC', 'OLTC+SC+SVC'], loc='upper right')
  plt.grid()
  plt.show()
  </code></pre>
  
  <p>But when I try running the code, I get the following output<a href="https://i.stack.imgur.com/yWcYX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yWcYX.png" alt="enter image description here"></a></p>
  
  <p>Does anyone know what I'm doing wrong or what I should do to get the desired output?</p>