<h3 dir="auto">Buggy case</h3>
<p dir="auto">The following example produces an empty figure:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax2 = ax1.twinx()
ax2.cla()
ax1.plot([1,2,3])
fig.savefig('test.png')"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax2 = ax1.twinx()
ax2.cla()
ax1.plot([1,2,3])
fig.savefig('test.png')
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/314716/6369582/1084aecc-bce8-11e4-970a-a7e7750b8c74.png"><img src="https://cloud.githubusercontent.com/assets/314716/6369582/1084aecc-bce8-11e4-970a-a7e7750b8c74.png" alt="test" style="max-width: 100%;"></a></p>
<h3 dir="auto">Control case</h3>
<p dir="auto">If I remove <code class="notranslate">twinx</code> it works:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax2 = ax1.twinx()
ax1.plot([1,2,3])
fig.savefig('test.png')"><pre class="notranslate"><code class="notranslate">import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
ax2 = ax1.twinx()
ax1.plot([1,2,3])
fig.savefig('test.png')
</code></pre></div>
<p dir="auto"><a target="_blank" rel="noopener noreferrer nofollow" href="https://cloud.githubusercontent.com/assets/314716/6369593/2d15caee-bce8-11e4-9a73-ef209384d12e.png"><img src="https://cloud.githubusercontent.com/assets/314716/6369593/2d15caee-bce8-11e4-9a73-ef209384d12e.png" alt="test" style="max-width: 100%;"></a></p>
<h3 dir="auto">Versions</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="$ python --version
Python 3.4.2 :: Continuum Analytics, Inc.
$ python -c 'import matplotlib; print(matplotlib.__version__)'
1.4.2"><pre class="notranslate"><code class="notranslate">$ python --version
Python 3.4.2 :: Continuum Analytics, Inc.
$ python -c 'import matplotlib; print(matplotlib.__version__)'
1.4.2
</code></pre></div>
<p dir="auto">With matplotlib 1.4.0 the cla() method for the twinx axes also clears the primary axes.  With matplotlib 1.3.1 the method only clears the twinx axes as expected.  I have a much longer program where the twinx axes must be cleared while retaining the primary axis plot.  I would prefer not to replot the entire graph each time the twinx axes change.  You can see this by adding the cla method to the matplotlib web site example, two_scales.py, shown below.</p>
<p dir="auto">I have matplotlib installed via the anaconda package. Matplotlib 1.4.0 is from anaconda 2.1.0.  Matplotlib 1.3.1 is from 1.9 versions of the anaconda package.</p>
<p dir="auto">Linux version:<br>
Linux gamow 3.2.0-4-amd64 <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="611170" data-permission-text="Title is private" data-url="https://github.com/matplotlib/matplotlib/issues/1" data-hovercard-type="pull_request" data-hovercard-url="/matplotlib/matplotlib/pull/1/hovercard" href="https://github.com/matplotlib/matplotlib/pull/1">#1</a> SMP Debian 3.2.60-1+deb7u3 x86_64 GNU/Linux<br>
Same cla() result on osX 10.9.4.</p>
<p dir="auto">Same result for backends Qt4Agg and TkAgg;  the cla() method cleared both axes.<br>
I also tried various other options such as setting ax2.hold(False) prior to replotting  ax2.  However, once again ax1 was cleared.  The ax2 clear commands seem to apply to the ax1 axis as well???  These options worked as expected  for the earlier matplotlib version, clearing only the ax2 axis.</p>
<p dir="auto">Here’s the code:  if you execute the code, you should see a blank figure with the cla() included and the usual two graphs without the cla() method.</p>
<hr>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import matplotlib.pyplot as plt

fig, ax1 = plt.subplots()
t = np.arange(0.01, 10.0, 0.01)
s1 = np.exp(t)
ax1.plot(t, s1, 'b-')
ax1.set_xlabel('time (s)')
# Make the y-axis label and tick labels match the line color.
ax1.set_ylabel('exp', color='b')
for tl in ax1.get_yticklabels():
    tl.set_color('b')

ax2 = ax1.twinx()
s2 = np.sin(2*np.pi*t)
ax2.plot(t, s2, 'r.')
ax2.set_ylabel('sin', color='r')
for tl in ax2.get_yticklabels():
    tl.set_color('r')

# single line addition to the two_scales.py example
# clears both ax2 and ax1 under matplotlib 1.4.0, clears only ax2 under matplotlib 1.3.1
# obviously, same result with ax2.clear() method
ax2.cla()

plt.show()"><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-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-s1">fig</span>, <span class="pl-s1">ax1</span> <span class="pl-c1">=</span> <span class="pl-s1">plt</span>.<span class="pl-en">subplots</span>()
<span class="pl-s1">t</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">arange</span>(<span class="pl-c1">0.01</span>, <span class="pl-c1">10.0</span>, <span class="pl-c1">0.01</span>)
<span class="pl-s1">s1</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">exp</span>(<span class="pl-s1">t</span>)
<span class="pl-s1">ax1</span>.<span class="pl-en">plot</span>(<span class="pl-s1">t</span>, <span class="pl-s1">s1</span>, <span class="pl-s">'b-'</span>)
<span class="pl-s1">ax1</span>.<span class="pl-en">set_xlabel</span>(<span class="pl-s">'time (s)'</span>)
<span class="pl-c"># Make the y-axis label and tick labels match the line color.</span>
<span class="pl-s1">ax1</span>.<span class="pl-en">set_ylabel</span>(<span class="pl-s">'exp'</span>, <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'b'</span>)
<span class="pl-k">for</span> <span class="pl-s1">tl</span> <span class="pl-c1">in</span> <span class="pl-s1">ax1</span>.<span class="pl-en">get_yticklabels</span>():
    <span class="pl-s1">tl</span>.<span class="pl-en">set_color</span>(<span class="pl-s">'b'</span>)

<span class="pl-s1">ax2</span> <span class="pl-c1">=</span> <span class="pl-s1">ax1</span>.<span class="pl-en">twinx</span>()
<span class="pl-s1">s2</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">sin</span>(<span class="pl-c1">2</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span><span class="pl-c1">*</span><span class="pl-s1">t</span>)
<span class="pl-s1">ax2</span>.<span class="pl-en">plot</span>(<span class="pl-s1">t</span>, <span class="pl-s1">s2</span>, <span class="pl-s">'r.'</span>)
<span class="pl-s1">ax2</span>.<span class="pl-en">set_ylabel</span>(<span class="pl-s">'sin'</span>, <span class="pl-s1">color</span><span class="pl-c1">=</span><span class="pl-s">'r'</span>)
<span class="pl-k">for</span> <span class="pl-s1">tl</span> <span class="pl-c1">in</span> <span class="pl-s1">ax2</span>.<span class="pl-en">get_yticklabels</span>():
    <span class="pl-s1">tl</span>.<span class="pl-en">set_color</span>(<span class="pl-s">'r'</span>)

<span class="pl-c"># single line addition to the two_scales.py example</span>
<span class="pl-c"># clears both ax2 and ax1 under matplotlib 1.4.0, clears only ax2 under matplotlib 1.3.1</span>
<span class="pl-c"># obviously, same result with ax2.clear() method</span>
<span class="pl-s1">ax2</span>.<span class="pl-en">cla</span>()

<span class="pl-s1">plt</span>.<span class="pl-en">show</span>()</pre></div>
<p dir="auto">I would appreciate any help;  this looks like a bug in the latest version of matplotlib.<br>
I could not find any reference to this problem in earlier posts.</p>
<p dir="auto">Thanks,<br>
Charlie</p>
<p dir="auto">[TAC edited for markup]</p>