我试图读取一个日期如下的csv文件:2018-02-20T22:41:33.793000Z,我无法弄清楚如何将其用作x轴在matplotlib中。我显然不知道我在日期时间做了什么,因为我似乎无法让它成为matplotlib的有用数字。
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sys
import os
import matplotlib
import matplotlib.dates as mdates
import datetime
from datetime import datetime
data = pd.read_csv(os.path.join(os.path.dirname(__file__), 'new.csv'))
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
b = data.iloc[:, 8] #reading from column 8
a = pd.to_datetime(b, format='%Y-%m-%dT%H:%M:%S.%fZ', errors='ignore')
print(a)
x = a #date #.iloc[:, 0] grabs column without header
y = data.iloc[:, 2] #number #reading from column 2
z = data.iloc[:, 6] #quantity #reading from column 6
#c = data.bluered #blue or red
ax.scatter(x, y, z) #ax.scatter(x, y, z, c=c)
plt.xlim(-1, 35)
plt.ylim(0, 300)
ax.set_zlim(-1,150)
plt.show()
答案 0 :(得分:0)
经过多次挫折后,我发现我遇到的问题只是将plt.xlim(-1,35)更改为plt.xlim(' 2018-02-20 22:41:26.419000' ,' 2018-02-20 22:48:55.768000')...这是我正在查看的日期/时间范围。