【发布时间】:2020-05-05 08:56:50
【问题描述】:
我正在家里做我学校的 Arduino 项目,老师让我为他可视化我的数据。在我的 x 轴上,我有超过 20K 的时间点需要显示,我尝试为其设置一个范围。
我想要实现的图表:
我到现在为止:
很明显我做错了什么,我已经研究了解决它的方法。
我的绘图部分的#部分是我从互联网上学到的,但它们在这里不起作用。
请帮助我,如果有任何不清楚的地方,请告诉我!
import csv
import matplotlib.pyplot as plt
from datetime import datetime
header = []
data = []
path="DATALOG.csv" #CHANGE filename to match file
file = open(path, newline='')
reader=csv.reader(file)
header=next(reader) #This reads the first row and stores the words in header.
data=[row for row in reader] #This reads the rest and store the data in a list
file.close() #closes the file when complete
# This function will print the headings with their index. Helpful when dealing with many columns
def print_header():
for index, column_header in enumerate(header):
print(index, column_header)
# I want the high and low temperatures in New Glasgow for June 2010
# Key headings
# 0 date/time
# 1 temperature
# 2 humidity %
# 3 light level%
days = []
light = []
for row in range (len(data)):
day = data[row][0]
lights = data[row][3]
current_date=datetime.strptime(data[row][0], "%A %H:%M:%S %d/%m/%Y")
light.append(float(lights)) #store the day’s high temp in list
#store the day’s low temp in list
days.append(str(day))
fig = plt.figure(dpi=128, figsize = (50, 6))
#x = [dc[0] for dc in days]
#xticks = range(0,len(x),10)
#xlabels=[x[index] for index in xticks]
#xticks.append(len(x))
#xlabels.append(days[-1][0])
#ax.set_xticks(xtick)
#ax.set_xticklabels(xlabels,rotation=40)
plt.plot(days,light,c = 'red',label = 'temprature')
plt.title("LIGHT")
plt.xlabel('days',fontsize = 5)
#ax.plot(np.arange('Wednesday 12:00:00 08/01/2020',' Thursday 11:58:10 09/01/2020'), range(10))
fig.autofmt_xdate()
plt.ylabel('light (%)', fontsize = 12)
plt.tick_params(axis='both', which='major', labelsize = 10)
plt.legend()
plt.show()
plt.savefig('plot.png')
【问题讨论】:
-
您是否正在寻找使用 r 的解决方案?如果是这样,您能否提供一个可重复的小数据集示例? (在这里查看操作方法:stackoverflow.com/questions/5963269/…)
-
欢迎来到 SO!如果您查看How do I ask and answer homework questions? 并修改您的问题,我认为您可以提高获得答案的机会。
-
感谢您回复我!我真的很难解释我的想法,因为我是 python 菜鸟和英语学习者!
标签: python r matplotlib range axis