title: Can I mimic a log scale of an axis in matplotlib without transforming the associated data?
body: <p>I am trying to display a <a href="https://en.wikipedia.org/wiki/Zipf%27s_law" rel="nofollow noreferrer">Zipf plot</a>, which is typically displayed on a log-log scale.</p>
  
  <p>I'm using a library which gives rank in linear scale and frequencies in log scale. I have the following code which plots my data fairly correctly:</p>
  
  <pre><code>ranks = [3541, 60219, 172644, 108926, 733215, 1297533, 1297534, 1297535]
  # These frequencies are already log-scale
  freqs = [-10.932271003723145, -15.213129043579102, -17.091760635375977, -16.27560806274414, 
          -19.482173919677734, -19.502029418945312, -19.502029418945312, -19.502029418945312]
  
  data = {
      'ranks': ranks, 
      'freqs': freqs,
  }
  
  df = pd.DataFrame(data=data)
  
  _, ax = plt.subplots(figsize=(7, 7))
  ax.set(xscale="log", yscale="linear")
  ax.set_title("Zipf plot")
  sns.regplot("ranks", "freqs", data=df, ax=ax, fit_reg=False)
  ax.set_xlabel("Frequency rank of token")
  ax.set_ylabel("Absolute frequency of token")
  ax.grid(True, which="both")
  plt.show()
  </code></pre>
  
  <p>The resulting plot is:</p>
  
  <p><a href="https://i.stack.imgur.com/8qWHQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8qWHQ.png" alt="Zipf 1"></a></p>
  
  <p>The plot looks good, but the y-label is weird. I'd like it to be displayed in log-increments as well. My current workaround is to raise 10 to the power of each element in the <code>freqs</code> list; i.e.,</p>
  
  <pre><code>freqs = [10**freq for freq in freqs]
  # ...
  </code></pre>
  
  <p>and change the <code>yscale</code> in <code>ax.set</code> to log; i.e.,</p>
  
  <pre><code>_, ax = plt.subplots(figsize=(7, 7))
  ax.set(xscale="log", yscale="log")
  ax.set_title("Zipf plot")
  # ...
  </code></pre>
  
  <p>This gives me the expected plot (below), but it requires a transform of the data which is a) relatively expensive, b) redundant, c) lossy.</p>
  
  <p><a href="https://i.stack.imgur.com/lfjWJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lfjWJ.png" alt="Zipf 2"></a></p>
  
  <p>Is there a way to mimic the log scale of the axes in a matplotlib plot <em>without</em> transforming the data?</p>