title: Set y ticks in logscale Boxplots: Matplotlib
body: <p>I am plotting boxplots of some data in the range of 0 to 20 on a log scale. I want to set a custom starting and ending ticks. All the other ticks should be in the log scale aswell (2 * 10^-1).</p>
  <p>I tried using <code>ax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '{:g}'.format(y)))</code>
  doesn't work<br />
  Also</p>
  <pre><code>ymin = min - 0.1 * (max - min)
  ymax = max + 0.1 * (max - min)
  plt.ylim(ymin, ymax)
  </code></pre>
  <p>gives the warning:</p>
  <pre><code>Invalid limit will be ignored.
    plt.ylim(ymin, ymax)
  </code></pre>
  <p>here is the entire code:</p>
  <pre><code>import numpy as np
  import pandas as pd
  import matplotlib.pyplot as plt
  import seaborn as sns
  from matplotlib import ticker
  from math import log, exp
  
  log_scale = True
  min = 0
  max = 50
  
  atributes = []
  for i in [8, 10, 6, 12]:
      att = [i] * 50
      atributes.extend(att)
  values = np.random.uniform(1, 20, 200)
  
  df1 = pd.DataFrame({'Attributes': atributes, 'values': values})
  if min is None and max is not None:
      min = df1[&quot;values&quot;].min()
  if max is None and min is not None:
      max = df1[&quot;values&quot;].max()
  
  if min or max is not None:
      df1 = df1[(min &lt;= df1[&quot;values&quot;]) &amp; (df1[&quot;values&quot;] &lt;= max)]
  
  plt.figure()
  sns.set_style(&quot;whitegrid&quot;)
  ax = None
  
  ax = sns.boxplot(x='Attributes', y='values', data=df1, color=&quot;white&quot;)
  
  if log_scale:
      plt.yscale('log')
      ax.yaxis.set_major_formatter(ticker.FuncFormatter(lambda y, _: '{:g}'.format(y)))
  
  if min is not None:
      try:
          min, max = log(min), log(max)
      except ValueError:
          min = 0
          max = log(max)
      ymin = min - 0.1 * (max - min)
      ymax = max + 0.1 * (max - min)
      plt.ylim(exp(ymin), exp(ymax))
  
  fig = plt.gcf()
  fig.set_size_inches(10.5, 8)
  plt.show()
  
  </code></pre>
  <p>Here is how the plot looks like:</p>
  <p><a href="https://i.stack.imgur.com/NEXPW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NEXPW.jpg" alt="Boxplot of atributes" /></a></p>