<h3 dir="auto">Bug report</h3>
<p dir="auto"><strong>Bug summary</strong></p>
<p dir="auto">I use a custom tick formatter in my plot. It worked great with an older version of matplotlib but I just upgraded to 2.0 and I see overlapping tickmark labels (the default labels are still there):</p>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/738893/24481436/17ce6b6c-149f-11e7-98b1-fcc73fc084d4.png"><img src="https://cloud.githubusercontent.com/assets/738893/24481436/17ce6b6c-149f-11e7-98b1-fcc73fc084d4.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import matplotlib
import matplotlib.pyplot as plt


class MyLogFormatter(matplotlib.ticker.LogFormatter):
    def __call__(self, x, pos=None):
        e = np.floor(np.log10(x))
        m = x/(10**e)
        if x &lt; 0.01:
            return '%de%d' % (round(m), e)
        elif x &lt; 1:
            return '%.2f' % x
        elif x &lt; 10:
            return '%.1f' % x
        elif x &lt; 1000:
            return '%.0f' % x
        else:
            return '%de%d' % (round(m), e)
    @staticmethod
    def ticks(xmin, xmax):
        ndecades = np.ceil(np.log10(xmax/xmin))
        if ndecades &gt; 6:
            mantissas = [1]
        elif ndecades &gt; 3:
            mantissas = [1,3]
        else:
            mantissas = [1,2,5]
        roundnumbers = (10**np.arange(np.floor(np.log10(xmin)), np.ceil(np.log10(xmax)))*np.atleast_2d(mantissas).T).T.flatten()
        return np.hstack((xmin, [x for x in roundnumbers if xmin*1.25 &lt; x &lt; 0.8*xmax], xmax))        

data = 0
for k in xrange(4):
    data += np.random.randint(6, size=100000)
    
count,edges = np.histogram(data,10)
x = 100 * (1.1 ** edges)

fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(1,1,1,xscale='log')
ax.bar(x[:-1], count, width=x[1:] - x[:-1], color='red',edgecolor='black',align='edge')
xmin = min(x)
xmax = max(x)
LF = MyLogFormatter(labelOnlyBase=False)
ax.set_xticks(LF.ticks(xmin, xmax))
ax.xaxis.set_major_formatter(LF)     "><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>


<span class="pl-k">class</span> <span class="pl-v">MyLogFormatter</span>(<span class="pl-s1">matplotlib</span>.<span class="pl-s1">ticker</span>.<span class="pl-v">LogFormatter</span>):
    <span class="pl-k">def</span> <span class="pl-en">__call__</span>(<span class="pl-s1">self</span>, <span class="pl-s1">x</span>, <span class="pl-s1">pos</span><span class="pl-c1">=</span><span class="pl-c1">None</span>):
        <span class="pl-s1">e</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">floor</span>(<span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-s1">x</span>))
        <span class="pl-s1">m</span> <span class="pl-c1">=</span> <span class="pl-s1">x</span><span class="pl-c1">/</span>(<span class="pl-c1">10</span><span class="pl-c1">**</span><span class="pl-s1">e</span>)
        <span class="pl-k">if</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">0.01</span>:
            <span class="pl-k">return</span> <span class="pl-s">'%de%d'</span> <span class="pl-c1">%</span> (<span class="pl-en">round</span>(<span class="pl-s1">m</span>), <span class="pl-s1">e</span>)
        <span class="pl-k">elif</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">1</span>:
            <span class="pl-k">return</span> <span class="pl-s">'%.2f'</span> <span class="pl-c1">%</span> <span class="pl-s1">x</span>
        <span class="pl-k">elif</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">10</span>:
            <span class="pl-k">return</span> <span class="pl-s">'%.1f'</span> <span class="pl-c1">%</span> <span class="pl-s1">x</span>
        <span class="pl-k">elif</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">1000</span>:
            <span class="pl-k">return</span> <span class="pl-s">'%.0f'</span> <span class="pl-c1">%</span> <span class="pl-s1">x</span>
        <span class="pl-k">else</span>:
            <span class="pl-k">return</span> <span class="pl-s">'%de%d'</span> <span class="pl-c1">%</span> (<span class="pl-en">round</span>(<span class="pl-s1">m</span>), <span class="pl-s1">e</span>)
    <span class="pl-en">@<span class="pl-s1">staticmethod</span></span>
    <span class="pl-k">def</span> <span class="pl-en">ticks</span>(<span class="pl-s1">xmin</span>, <span class="pl-s1">xmax</span>):
        <span class="pl-s1">ndecades</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">ceil</span>(<span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-s1">xmax</span><span class="pl-c1">/</span><span class="pl-s1">xmin</span>))
        <span class="pl-k">if</span> <span class="pl-s1">ndecades</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">6</span>:
            <span class="pl-s1">mantissas</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>]
        <span class="pl-k">elif</span> <span class="pl-s1">ndecades</span> <span class="pl-c1">&gt;</span> <span class="pl-c1">3</span>:
            <span class="pl-s1">mantissas</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>,<span class="pl-c1">3</span>]
        <span class="pl-k">else</span>:
            <span class="pl-s1">mantissas</span> <span class="pl-c1">=</span> [<span class="pl-c1">1</span>,<span class="pl-c1">2</span>,<span class="pl-c1">5</span>]
        <span class="pl-s1">roundnumbers</span> <span class="pl-c1">=</span> (<span class="pl-c1">10</span><span class="pl-c1">**</span><span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-s1">np</span>.<span class="pl-en">floor</span>(<span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-s1">xmin</span>)), <span class="pl-s1">np</span>.<span class="pl-en">ceil</span>(<span class="pl-s1">np</span>.<span class="pl-en">log10</span>(<span class="pl-s1">xmax</span>)))<span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-en">atleast_2d</span>(<span class="pl-s1">mantissas</span>).<span class="pl-v">T</span>).<span class="pl-v">T</span>.<span class="pl-en">flatten</span>()
        <span class="pl-k">return</span> <span class="pl-s1">np</span>.<span class="pl-en">hstack</span>((<span class="pl-s1">xmin</span>, [<span class="pl-s1">x</span> <span class="pl-k">for</span> <span class="pl-s1">x</span> <span class="pl-c1">in</span> <span class="pl-s1">roundnumbers</span> <span class="pl-k">if</span> <span class="pl-s1">xmin</span><span class="pl-c1">*</span><span class="pl-c1">1.25</span> <span class="pl-c1">&lt;</span> <span class="pl-s1">x</span> <span class="pl-c1">&lt;</span> <span class="pl-c1">0.8</span><span class="pl-c1">*</span><span class="pl-s1">xmax</span>], <span class="pl-s1">xmax</span>))        

<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-c1">0</span>
<span class="pl-k">for</span> <span class="pl-s1">k</span> <span class="pl-c1">in</span> <span class="pl-en">xrange</span>(<span class="pl-c1">4</span>):
    <span class="pl-s1">data</span> <span class="pl-c1">+=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">randint</span>(<span class="pl-c1">6</span>, <span class="pl-s1">size</span><span class="pl-c1">=</span><span class="pl-c1">100000</span>)
    
<span class="pl-s1">count</span>,<span class="pl-s1">edges</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">histogram</span>(<span class="pl-s1">data</span>,<span class="pl-c1">10</span>)
<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-c1">100</span> <span class="pl-c1">*</span> (<span class="pl-c1">1.1</span> <span class="pl-c1">**</span> <span class="pl-s1">edges</span>)

<span class="pl-s1">fig</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">figure</span>(<span class="pl-s1">figsize</span><span class="pl-c1">=</span>(<span class="pl-c1">8</span>,<span class="pl-c1">6</span>))
<span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">fig</span>.<span class="pl-en">add_subplot</span>(<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-c1">1</span>,<span class="pl-s1">xscale</span><span class="pl-c1">=</span><span class="pl-s">'log'</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">bar</span>(<span class="pl-s1">x</span>[:<span class="pl-c1">-</span><span class="pl-c1">1</span>], <span class="pl-s1">count</span>, <span class="pl-s1">width</span><span class="pl-c1">=</span><span class="pl-s1">x</span>[<span class="pl-c1">1</span>:] <span class="pl-c1">-</span> <span class="pl-s1">x</span>[:<span class="pl-c1">-</span><span class="pl-c1">1</span>], <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'red'</span>,<span class="pl-s1">edgecolor</span><span class="pl-c1">=</span><span class="pl-s">'black'</span>,<span class="pl-s1">align</span><span class="pl-c1">=</span><span class="pl-s">'edge'</span>)
<span class="pl-s1">xmin</span> <span class="pl-c1">=</span> <span class="pl-en">min</span>(<span class="pl-s1">x</span>)
<span class="pl-s1">xmax</span> <span class="pl-c1">=</span> <span class="pl-en">max</span>(<span class="pl-s1">x</span>)
<span class="pl-v">LF</span> <span class="pl-c1">=</span> <span class="pl-v">MyLogFormatter</span>(<span class="pl-s1">labelOnlyBase</span><span class="pl-c1">=</span><span class="pl-c1">False</span>)
<span class="pl-s1">ax</span>.<span class="pl-en">set_xticks</span>(<span class="pl-v">LF</span>.<span class="pl-en">ticks</span>(<span class="pl-s1">xmin</span>, <span class="pl-s1">xmax</span>))
<span class="pl-s1">ax</span>.<span class="pl-s1">xaxis</span>.<span class="pl-en">set_major_formatter</span>(<span class="pl-v">LF</span>)     </pre></div>
<p dir="auto"><strong>Actual outcome</strong></p>
<ul dir="auto">
<li>The output produced by the above code, which may be a screenshot, console output, etc.</li>
</ul>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/738893/24481436/17ce6b6c-149f-11e7-98b1-fcc73fc084d4.png"><img src="https://cloud.githubusercontent.com/assets/738893/24481436/17ce6b6c-149f-11e7-98b1-fcc73fc084d4.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">previous version was Matplotlib 1.5.1<br>
(can't post right now, I will have to downgrade my anaconda version)</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<ul dir="auto">
<li>Matplotlib 2.0<br>
<code class="notranslate">Python 2.7.12 |Anaconda 4.1.1 (64-bit)| (default, Jun 29 2016, 11:07:13) [MSC v.1500 64 bit (AMD64)] on win32</code></li>
</ul>
<h3 dir="auto">Bug report</h3>
<p dir="auto">contourf produces wrongly formatted plot labels for logarithmic plots when there is only one order of magnitude or less of range of data (eg. 10 to 100 or 100 to 1000).</p>
<p dir="auto"><strong>Code for reproduction</strong></p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt
from matplotlib.ticker import StrMethodFormatter
import numpy as np
t = np.linspace(0,1000,1001)
p = np.array([10,20,30,40,50,60,70,80,90,100])
data = np.random.random_sample((len(p),len(t)))
pressure,time = np.meshgrid(p,t)

fig, ax = plt.subplots(nrows=2)
ax1, ax2 = tuple(ax)
ax1.contourf(time,pressure,data.T)
ax1.set_yscale('log')
ax1.set_yticks([10,30,100])
ax1.get_yaxis().set_major_formatter(StrMethodFormatter('{x:.0f}'))
ax2.plot(p)
ax2.set_yscale('log')
ax2.set_yticks([10,30,100])
ax2.get_yaxis().set_major_formatter(StrMethodFormatter('{x:.0f}'))
plt.show()"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">ticker</span> <span class="pl-k">import</span> <span class="pl-v">StrMethodFormatter</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>,<span class="pl-c1">1000</span>,<span class="pl-c1">1001</span>)
<span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">array</span>([<span class="pl-c1">10</span>,<span class="pl-c1">20</span>,<span class="pl-c1">30</span>,<span class="pl-c1">40</span>,<span class="pl-c1">50</span>,<span class="pl-c1">60</span>,<span class="pl-c1">70</span>,<span class="pl-c1">80</span>,<span class="pl-c1">90</span>,<span class="pl-c1">100</span>])
<span class="pl-s1">data</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-s1">random</span>.<span class="pl-en">random_sample</span>((<span class="pl-en">len</span>(<span class="pl-s1">p</span>),<span class="pl-en">len</span>(<span class="pl-s1">t</span>)))
<span class="pl-s1">pressure</span>,<span class="pl-s1">time</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">meshgrid</span>(<span class="pl-s1">p</span>,<span class="pl-s1">t</span>)

<span class="pl-s1">fig</span>, <span class="pl-s1">ax</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>(<span class="pl-s1">nrows</span><span class="pl-c1">=</span><span class="pl-c1">2</span>)
<span class="pl-s1">ax1</span>, <span class="pl-s1">ax2</span> <span class="pl-c1">=</span> <span class="pl-en">tuple</span>(<span class="pl-s1">ax</span>)
<span class="pl-s1">ax1</span>.<span class="pl-en">contourf</span>(<span class="pl-s1">time</span>,<span class="pl-s1">pressure</span>,<span class="pl-s1">data</span>.<span class="pl-v">T</span>)
<span class="pl-s1">ax1</span>.<span class="pl-en">set_yscale</span>(<span class="pl-s">'log'</span>)
<span class="pl-s1">ax1</span>.<span class="pl-en">set_yticks</span>([<span class="pl-c1">10</span>,<span class="pl-c1">30</span>,<span class="pl-c1">100</span>])
<span class="pl-s1">ax1</span>.<span class="pl-en">get_yaxis</span>().<span class="pl-en">set_major_formatter</span>(<span class="pl-v">StrMethodFormatter</span>(<span class="pl-s">'{x:.0f}'</span>))
<span class="pl-s1">ax2</span>.<span class="pl-en">plot</span>(<span class="pl-s1">p</span>)
<span class="pl-s1">ax2</span>.<span class="pl-en">set_yscale</span>(<span class="pl-s">'log'</span>)
<span class="pl-s1">ax2</span>.<span class="pl-en">set_yticks</span>([<span class="pl-c1">10</span>,<span class="pl-c1">30</span>,<span class="pl-c1">100</span>])
<span class="pl-s1">ax2</span>.<span class="pl-en">get_yaxis</span>().<span class="pl-en">set_major_formatter</span>(<span class="pl-v">StrMethodFormatter</span>(<span class="pl-s">'{x:.0f}'</span>))
<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto"><strong>Actual outcome</strong><br>
Using matplotlib 2.0.0 the labelling of the y-axis of the contour plot is messed up compared to the y-axis of the line plot.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/17760178/24348397/e0b2d998-12db-11e7-9770-de019b061951.png"><img src="https://cloud.githubusercontent.com/assets/17760178/24348397/e0b2d998-12db-11e7-9770-de019b061951.png" alt="logtest2" style="max-width: 100%;"></a><br>
Remark: The default color map was used.</p>
<p dir="auto"><strong>Expected outcome</strong></p>
<p dir="auto">Using matplotlib 1.5.1 the labelling of the y-axis of the contour plot is as beautiful as the labelling of the y-axis of the line plot.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/17760178/24348717/f40bc102-12dc-11e7-9483-829919313e32.png"><img src="https://cloud.githubusercontent.com/assets/17760178/24348717/f40bc102-12dc-11e7-9483-829919313e32.png" alt="logtest2" style="max-width: 100%;"></a><br>
Remark: The default color map was used.</p>
<p dir="auto"><strong>Matplotlib version</strong></p>
<p dir="auto">matplotlib 2.0.0 (installed using pip)<br>
python 3.6.1 (installed using brew)<br>
macos</p>