我正在绘制一个天气数据的 CSV 文件,并且在我的代码中可以很好地导入它,但我正在尝试绘制它。以下是 CSV 数据的示例:
12:00am,171,6,7,52,76,77.1,63.7,28.74,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
12:01am,192,4,6,52,76,77.1,63.7,28.74,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
12:02am,197,3,6,52,76,77.1,63.7,28.74,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
12:03am,175,3,6,52,76,77.1,63.7,28.73,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
12:04am,194,4,6,52,76,77.1,63.7,28.73,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
12:05am,148,5,6,52,76,77.1,63.7,28.73,0.00,0.00,0.0,0,63.7,78.1,67.4,56.0,29.96
无论如何,我希望时间在 X 轴上,但我无法使用 matplotlib 进行绘图。我尝试了一种使用 xticks 的方法,它绘制了我的 y 值,但仅此而已。它只是在我的 X 轴上给了我一条粗实线。
import matplotlib as mpl
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
from matplotlib.dates import date2num
import datetime as DT
import re
data = np.genfromtxt('FILE.csv', delimiter=',', dtype=None, skip_header=3)
length = len(data)
x = data['f0']
y = data['f7']
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_title("Temperature")
ax1.set_xlabel('Time')
ax1.set_ylabel('Degrees')
#plt.plot_date(x, y)
plt.show()
leg = ax1.legend()
plt.show()
我错过了一些关键部分,因为我真的不知道从这里去哪里。我检查了我的 numpy 数组的数据类型,它一直说 numpy.ndarray,我找不到将其转换为字符串或 int 值的方法来绘制。这是一个 24 小时 CSV 文件,我希望每 30 分钟左右打一个刻度线。有任何想法吗?