绘制数据时出现matplotlib语法错误

时间:2018-05-26 11:18:49

标签: python matplotlib

我试图使用matplotlib绘制可视化数据但我收到错误。这是我的代码:

import numpy as np
import datetime
import time
import matplotlib.pyplot as plt
import matplotlib.ticker as mticker
import matplotlib.dates as mdates

data=open('final1.csv','r')
date&time,values = np.genfromtxt(data,delimiter=',',unpack=True,converters={0: mdates.bytespdate2num("%d/%m/%Y %H:%M")})

plt.gca().xaxis.set_major_locator(mticker.MaxNLocator(10))
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter(('%d/%m/%Y %H:%M')))

plt.plot(date&time,values,color='red')

plt.ylabel('Values')
plt.xlabel('Date')

plt.gcf().autofmt_xdate()

plt.show()

我收到以下错误:

date&time,values => np.genfromtxt(data,delimiter=',',unpack=True,converters=0:mdates.bytespdate2num("%d/%m/%Y %H:%M")})  
    ^ SyntaxError: can't assign to operator

我的final.csv文件如下所示:

3/1/2017 13:00,746.76
3/1/2017 13:30,760.98
3/1/2017 14:00,742.98
3/1/2017 14:30,720.48
3/1/2017 15:00,705.42
3/1/2017 15:30,738.12
3/1/2017 16:00,734.82
3/1/2017 16:30,712.74
3/1/2017 17:00,726.96
3/1/2017 17:30,721.14
3/1/2017 18:00,695.94
3/1/2017 18:30,676.5

0 个答案:

没有答案