I'm having some issue getting my code to run. The two lines in question are as follows (the code runs fine without them).
ax1_2 = ax1.twinx()
ax1_2.fill_between(date, 0, (ask-bid), alpha = 3, facecolor='g')
I'm looking to twin their x's and show another plot ontop of my current graph (displaying spread for my data).
Here's my source code. Any help is much appreciated.
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()