title: matplotlib: how to simultaneously change tick position and figure shape
body: <p>I'm plotting a figure and hope to set the figure shape and tick positions. But I find that I cannot do the two things together. For example, if I use the following code:</p>
  <pre><code>import matplotlib
  import matplotlib.pyplot as plt
  
  ls = range(0,10)
  fig, ax = plt.subplots()
  # set figure shape
  plt.figure(figsize=(10,5))
  plt.ylim([0,10])
  plt.plot(ls)
  figname = 'aaa.jpg'
  # set ytick positions
  ax.set_yticks([1,3,5,7,9])
  plt.savefig(figname,format='jpg')
  </code></pre>
  <p>Then I get the following figure.
  <a href="https://i.stack.imgur.com/raKX5.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/raKX5.jpg" alt="enter image description here" /></a></p>
  <p>The shape is correct. But the <code>ytick</code> is not changed by the code line <code>ax.set_yticks([1,3,5,7,9])</code>.</p>
  <p>Then I try the following code (i.e. move the sentence <code>plt.figure(figsize=(10,5))</code> to the beginning of the program):</p>
  <pre><code>import matplotlib
  import matplotlib.pyplot as plt
  
  # set figure shape
  plt.figure(figsize=(10,5))
  ls = range(0,10)
  fig, ax = plt.subplots()
  plt.ylim([0,10])
  plt.plot(ls)
  figname = 'aaa.jpg'
  # set ytick position
  ax.set_yticks([1,3,5,7,9])
  plt.savefig(figname,format='jpg')
  </code></pre>
  <p>Then I get the following figure:</p>
  <p><a href="https://i.stack.imgur.com/R8hfH.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/R8hfH.jpg" alt="enter image description here" /></a></p>
  <p>The <code>ytick</code> is correct. Yicks appear in positions <code>[1,3,5,7,9]</code>. However, the figure shape is not the shape I set.</p>
  <p>How to do the two things together?</p>
  <p>Thank you all for helping me!!!</p>