title: matplotlib: set_yticks and ylim for categorical variables
body: <p>(Matplotlib version 2.2.2)</p>
  
  <p>I'm plotting some data where the values on the y-axis are discrete data.
  What I would like to do is to set the range of categories of the y-axis to also include values that are not appearing in the data set.
  Unfortunately I didn't find a way to add another category if it is not in the data.</p>
  
  <p>Also, I want to set a specific order of categories, as they're currently placed in order of appearance.</p>
  
  <p>Here is a MWE of what I currently have:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  fig = plt.figure()
  
  ax1 = fig.add_subplot(211)
  xs = list(range(10))
  ys = ["on", "off", "off", "on","on", "off", "off", "on", "on", "off"]
  ax1.plot(xs, ys)
  
  ax2 = fig.add_subplot(212)
  xs = list(range(10))
  ys = ["on", "on", "on", "on","on", "on", "on", "on", "on", "on"]
  ax2.plot(xs, ys)
  
  fig.show()
  </code></pre>
  
  <p>It produces the following output:
  <a href="https://i.stack.imgur.com/DfxhI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DfxhI.png" alt="MWE"></a></p>
  
  <p>I also want to show "off" on the y-axis of the bottom plot.</p>
  
  <hr>
  
  <p><strong>Current solution (not elegant, hoping for help):</strong></p>
  
  <p>My quickfix solution so far: I add a line with the category names in the order I want them and x-coordinate values that are not in the visible area (I can easily do this with x-coordinates when they're numeric, because I can set the limit). 
  I was however hoping that there is a more elegant solution (using the actual API or so).
  This solution is also not possible when the x-axis is also discrete as it's not possible to set limits, afaik.</p>
  
  <p>Quickfix source code (if somebody can use it):</p>
  
  <pre><code>...
  ax2 = fig.add_subplot(212)
  xs = list(range(10))
  ys = ["on", "on", "on", "on","on", "on", "on", "on", "on", "on"]
  ax2.set_xlim([0,(len(xs)-1)])
  ax2.plot(xs, ys)
  categories_in_order = ["on", "error", "off", "extra"]
  ax2.plot([-100] * len(categories_in_order), categories_in_order)
  ...
  </code></pre>
  
  <p>produces: <a href="https://i.stack.imgur.com/OBWYw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OBWYw.png" alt="enter image description here"></a></p>