Python: Matplotlib twin() issue: plotting spread
<p>I'm having some issue getting my code to run. The two lines in question are as follows (the code runs fine without them). </p>

<pre><code>ax1_2 = ax1.twinx()
ax1_2.fill_between(date, 0, (ask-bid), alpha = 3, facecolor='g')
</code></pre>

<p>I'm looking to twin their x's and show another plot ontop of my current graph (displaying spread for my data).</p>

<p>Here's my source code. Any help is much appreciated. </p>

<pre><code>import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np

from matplotlib import style
style.use('ggplot')


def bytespdate2num(fmt, encoding='utf-8'):
        strconverter = mdates.strpdate2num(fmt)
        def bytesconverter(b):
                s = b.decode(encoding)
                return strconverter(s)
        return bytesconverter

date_converter = bytespdate2num("%Y%m%d%H%M%S")

def graphRawFX():
    date,bid,ask=np.loadtxt('GBPUSD1d.txt', unpack=True,
                            delimiter=',',
                            converters = {0: date_converter})
    fig = plt.figure(figsize=(10,7))
    ax1 = plt.subplot2grid((40,40), (0,0), rowspan=40, colspan=40)

    ax1.plot(date,bid)
    ax1.plot(date,ask)
    plt.gca().get_yaxis().get_major_formatter().set_useOffset(False)
    # gca() here because we want to offset here

    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S'))
    for label in ax1.xaxis.get_ticklabels():
        label.set_rotation(45)

    ax1_2 = ax1.twinx()
    ax1_2.fill_between(date, 0, (ask-bid), alpha = 3, facecolor='g') #fills betwween date and zero, ask-bid is the spread

    plt.subplots_adjust(bottom=0.23)


    plt.grid(True)
    plt.show()

graphRawFX()
</code></pre>

<p>From our comments to the OP, your <code>alpha</code> value is too big.  It has to be between 0 and 1.  See <a href="http://stackoverflow.com/questions/4320021/matplotlib-transparent-line-plots">here</a> or the <a href="http://matplotlib.org/api/artist_api.html#matplotlib.artist.Artist.set_alpha" rel="nofollow">doc</a>.  What you want is</p>

<pre><code>ax1_2.fill_between(date, 0, (ask-bid), alpha = 0.3, facecolor='g')
</code></pre>

python matplotlib