title: Drawing hatch filled rectangles with differing angles in python
body: <p>I'm trying to draw a 2D rectangular plate in python. This plate will be split into a variable number of sections, each of these sections will be filled with a hatched pattern. This hatched pattern will have a specified angle. As an example for a rectangle with 5 sections and an array of its section hatch orientation (in degrees) being [0, 45, 0, -45, 0] is shown below. It will need to be able to display any orientation, not just the usual 90, 45, 0, i.e. 33, 74.5 etc.</p>
  
  <p><img src="https://i.stack.imgur.com/lfZXI.jpg" alt="enter image description here"></p>
  
  <p>Any idea how I could do this? Essentially I just want to show the orientation in each section, any other methods of expressing the same results would be much appreciated e.g. a single line instead of hatched.</p>
  
  <p>Edit (after question was answered):
  Edited script provided by Greg is shown below.</p>
  
  <pre><code>from numpy import cos, sin
  import numpy as np
  import matplotlib.pyplot as plt
  
  angles = [0,10,20,30,40,50]
  
  numberOfSections = len(angles)
  
  def plot_hatches(ax, angle, offset=.1):
      angle_radians = np.radians(angle)
      x = np.linspace(-1, 1, 10)
      for c in np.arange(-2, 2, offset):
          yprime = cos(angle_radians) * c - sin(angle_radians) * x
          xprime = sin(angle_radians) * c + cos(angle_radians) * x
          ax.plot(xprime, yprime, color="b", linewidth=2)
      ax.set_ylim(0, 1)
      ax.set_xlim(0, 1)
      return ax
  
  fig, axes = plt.subplots(nrows=1, ncols=numberOfSections, figsize=(16,(16/numberOfSections)), sharex=True, sharey=True)
  
  for i in range(len(axes.flat)):
      plot_hatches(axes.flat[i], angles[i])
  
  fig.subplots_adjust(hspace=0, wspace=0)  
  plt.show()
  </code></pre>
  
  <p>Produces an figure shown below.
  <img src="https://i.stack.imgur.com/UwdSb.png" alt="enter image description here">
  But on inspection the angles do not match the input angles.</p>