我有一些錯誤,當我嘗試並繪製了一些數據:如何解決「NameError:Name'日期'未定義」?
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
import numpy as np
import pylab
pylab.show()
from matplotlib import style
style.use("ggplot")
def graphRawFX(): date,bid,ask = np.loadtxt('XAUUSDS.txt', unpack=True,
delimiter='\t' ,
converters={0:mdates.strpdate2num('%d%m%Y%H%M%S%F')})
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)
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d%m%Y %H:%M:%S:%F.'))
for label in ax1.xaxis.get_ticklabels(): label.set_rotation(45)
plt.subplotls_adjust(bottom=.23)
plt.gca().get_yaxis().get_major_formatter().setuseoffset(False)
plt.grid(True)
plt.show()
graphRawFX()
plt.savefig('foo.png')
我得到的錯誤是:
NameError: Name 'date' is not defined
解決您的間距, – cwallenpoole