title: Creating an Exact Duplicate Secondary X/Y Axis with imshow
body: <p>I'm looking to put a secondary axis on my color grid I've created with matplotlib.pyplot.imshow.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from matplotlib.colors import LinearSegmentedColormap
  import matplotlib.patches as mpatches
  import numpy as np
  import struct
  
  colornames = ['LG','MSH','AS','LM','DB','TS','DG']
  hexvalues = ['B0AFA6', '988D81', '92909A','976F6F','5E4D43','D1BFA9','2F353F']
  pvalues = np.array([[0.20,0.40,0.20,0.05,0.05,0.05,0.05]])
  rows = 30
  cols = 52
  
  for iPDistInd in range(len(pvalues)):
      plt.figure()
      for iSubPlot in [221, 222, 223, 224]:
          ax = plt.subplot(iSubPlot)
          hexdata = np.random.choice(hexvalues,(rows,cols),p=pvalues[iPDistInd])
          rgbdata = [[struct.unpack('BBB',bytes.fromhex(y)) for y in x] for x in hexdata]
  
  
          im = plt.imshow(rgbdata, interpolation=None,
                          extent=[0.5, 0.5+cols, 0.5, 0.5+rows])
  
          plt.grid(True, which='both')
          ax.set_xlim(0,cols+1)
          ax.set_ylim(0,rows+1)
          ax.set_xticks(np.arange(0,cols+1,1))
          ax.set_yticks(np.arange(0,rows+1,1))
          ax.tick_params(axis='x', colors='green')
          ax.tick_params(axis='y', colors='blue')
          plt.suptitle(str(list(zip(colornames,pvalues[iPDistInd]))))
          plt.tight_layout(rect=[0, 0.03, 1, 0.95])
  plt.show()
  </code></pre>
  
  <p>But all the documentation I can find on <a href="https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.axes.Axes.secondary_yaxis.html" rel="nofollow noreferrer">secondary_xaxis</a> and <a href="https://matplotlib.org/3.1.1/api/_as_gen/matplotlib.axes.Axes.twinx.html" rel="nofollow noreferrer">twinx()</a> coupled with <a href="https://matplotlib.org/3.1.3/gallery/ticks_and_spines/tick-locators.html" rel="nofollow noreferrer">tick locators</a> are focused around creating a <em>different</em> axis on the secondary axis. Other stack overflow answers are similar.</p>
  
  <p><strong>I just want a one-to-one copy of the x and y axes on the 'top' and 'right'.</strong></p>
  
  <p>Adding </p>
  
  <pre><code>        ax2 = ax.secondary_xaxis('top')
          ay2 = ax.secondary_yaxis('right')
  </code></pre>
  
  <p>inside he for loop is closest I can get, but then I'm not sure how to manipulate the x and y ticks such that they match the 'bottom' and 'left' axes.
  (Yes, I know the labeling is quite crowded, but once I print to .pdf then there's enough space to read them.)</p>
  
  <p>Any advice?</p>