|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
import random
import matplotlib.pyplot as plt
fig = plt.figure()
ax = plt.gca()
x = []
y = []
i=0
plt.ion()
while True:
x.append(i)
y.append(random.randint(1,1000))
plt.xlim([0, 5000])
plt.ylim([0,1500])
plt.title('Scatter Graph')
plt.grid(True)
plt.plot(x,y,'y',linewidth=1)
plt.pause(0.05)
i += 50
这个代码的横坐标是数字,请问如何改成时间,比如9:00-16:00,每个刻度为1分钟
是这样么?
- import random
- import matplotlib.pyplot as plt
- import pandas as pd
- fig = plt.figure()
- ax = plt.gca()
- x = []
- y = []
- i=0
- plt.ion()
- time_range=pd.date_range(start='09:00',end='16:00',periods=6)
- time_range=[str(i).split(' ')[-1][0:5] for i in time_range]
- ax.set_xticklabels(time_range)
- fig.autofmt_xdate() #自适应调整
- while True:
- x.append(i)
- y.append(random.randint(1,1000))
- plt.xlim([0, 5000])
- plt.ylim([0,1500])
- plt.title('Scatter Graph')
- plt.grid(True)
- plt.plot(x,y,'y',linewidth=1)
- plt.pause(0.05)
- i += 50
复制代码
|
|