周期性分析就是探索某个变量是否随着时间的变化而呈现出周期性变化的趋势。具体的周期时间的选取可以根据情况而自定。
具体的代码展现如下:
我遇到的问题:
解决办法:
已解决SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated_(unicode error)'unicodeescape_袁袁袁袁满的博客-CSDN博客已解决(Python读取文件报错)SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: truncated \UXXXXXXXX escapehttps://blog.csdn.net/yuan2019035055/article/details/126368281?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167851237716800197070501%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=167851237716800197070501&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-1-126368281-null-null.142^v73^insert_down1,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=SyntaxError%3A%20%28unicode%20error%29%20unicodeescape%20codec%20cant%20decode%20bytes%20in%20position%2036-37%3A%20truncated%20%5CuXXXX%20escape&spm=1018.2226.3001.4187
我遇到的问题:
不知道如何设置x轴的间隔
解决办法:
python 画图自定义x轴刻度值_python x轴刻度_Weiyaner的博客-CSDN博客x = [1,3,5,7,9]plt.xticks(range(len(x)),x)https://blog.csdn.net/weixin_42327752/article/details/118419664?ops_request_misc=&request_id=&biz_id=102&utm_term=x_major_locator=multiplelocato&utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-1-118419664.142^v73^insert_down1,201^v4^add_ask,239^v2^insert_chatgpt&spm=1018.2226.3001.4187
我遇到的问题:
不知道gca()函数的用法
解决办法:
https://blog.csdn.net/weixin_46649052/article/details/107424134?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167851793516800225552046%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=167851793516800225552046&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-107424134-null-null.142^v73^insert_down1,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=ax%20%3D%20plt.gca%28%29%E7%9A%84%E4%BD%9C%E7%94%A8&spm=1018.2226.3001.4187https://blog.csdn.net/weixin_46649052/article/details/107424134?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167851793516800225552046%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=167851793516800225552046&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~first_rank_ecpm_v1~rank_v31_ecpm-2-107424134-null-null.142^v73^insert_down1,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=ax%20%3D%20plt.gca%28%29%E7%9A%84%E4%BD%9C%E7%94%A8&spm=1018.2226.3001.4187
目前plot里面绘图的方法总结:
使用python绘制折线图_python画折线图_焦糖呱呱子的博客-CSDN博客使用Python绘图,气象绘图https://blog.csdn.net/linxi4165/article/details/126086680?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522167851814116800182113179%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=167851814116800182113179&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~all~baidu_landing_v2~default-3-126086680-null-null.142^v73^insert_down1,201^v4^add_ask,239^v2^insert_chatgpt&utm_term=set_major_locator&spm=1018.2226.3001.4187
具体代码展示:
# 代码3-7 某单位日用电量预测分析import pandas as pd#导入pandas库,并且用pd表示
import matplotlib.pyplot as plt#导入pyplot库,并用plt表示df_normal = pd.read_csv(r"D:\DataMiningCode\chapter3\demo\data\user.csv")#为保持字符原始值的意思,而不会出现python中\加上其他的字符出现换行等其他的
#意思的情况,在路径的最开始加上r即可
plt.figure(figsize=(8,4))#设置画布大小
plt.plot(df_normal["Date"],df_normal["Eletricity"])#这里设置了做出来的图的自变量和因变量,前一个是自变量,后一个是因变量
plt.xlabel("日期")#x轴的标签设置为"日期"
plt.ylabel("每日电量")#y轴的标签设置为"每日电量"# 设置x轴刻度间隔
x_major_locator = plt.MultipleLocator(7)#这里x横坐标的间隔设置为7,用的就是这个固定的语句方法
ax = plt.gca()#gca()函数用来获取目前的轴,这里用ax来标记x轴
ax.xaxis.set_major_locator(x_major_locator)#set_major_locator用来修改主刻度的单位显示,这里修改x轴的主刻度显示为之前设置好的7
plt.title("正常用户电量趋势")#设置标题
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.show() # 展示图片# 窃电用户用电趋势分析
df_steal = pd.read_csv(r"D:\DataMiningCode\chapter3\demo\data\Steal user.csv")#标记已读文件
plt.figure(figsize=(10, 9))#设置画布大小
plt.plot(df_steal["Date"],df_steal["Eletricity"])#设置自变量因变量
plt.xlabel("日期")#设置x轴的标签
plt.ylabel("日期")#设置y轴的标签
# 设置x轴刻度间隔
x_major_locator = plt.MultipleLocator(7)#用x_major_locator标记刻度间隔为7的x轴
ax = plt.gca()#获取目前的x轴
ax.xaxis.set_major_locator(x_major_locator)#修改主刻度的单位显示
plt.title("窃电用户电量趋势")#设置标题
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.show() # 展示图片
运行结果: