Matplotlib subplots where one graph has multiple lines with and one doesn't
<p>currently trying this:</p>

<pre><code>fig, ax1, ax3 = plt.subplots(1, 2, figsize=(10,5))

# share rate line and ax
ax1.plot(temp_df.index, temp_df['share_rate'], 'b-')
ax1.set_ylim([0,.03])

# % of total video views line and ax
ax2 = ax1.twinx()
ax2.plot(temp_df.index, temp_df['percent_of_total_views'], 'r-')

# third plot
ax3.plot([1,2,3,4], [1,2,3,4])

plt.show()
</code></pre>

<p>but receiving this error:</p>

<pre><code>---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
&lt;ipython-input-62-a8364e1f65f8&gt; in &lt;module&gt;()
     10     print "average share rate: "
     11 
---&gt; 12     fig, ax1, ax3 = plt.subplots(1, 2, figsize=(10,5))
     13 
     14     # share rate line and ax

ValueError: need more than 2 values to unpack
</code></pre>

<p>You are using matplotlibs <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots" rel="nofollow">subplots-function</a> in a wrong way.</p>

<p>The statement of yours</p>

<pre><code>fig, ax1, ax3 = plt.subplots(1, 2, figsize=(10,5))  # WRONG 3 vars on left, 2 are returned
</code></pre>

<p>expects a tuple of size 3 returned, which are put into <code>fig, ax1, ax3</code>.</p>

<p>But the function returns only a tuple of size 2, <code>fig, ax</code> where ax can be a single axis, or a sequence of axis-objects (see docs).</p>

<p>If you know, that this ax is a sequence of size 2, you could unpack it directly on the left side with:</p>

<pre><code>fig, (ax1, ax3) = plt.subplots(1, 2, figsize=(10,5))  # CORRECT because 2nd return-value unpacked
</code></pre>

python matplotlib