# -*- coding: utf-8 -*-
# @Time : 2022/9/24 10:31
# @Author : Tiger大队队长
import matplotlib.pyplot as plt
import pandas as pd
# plt.rcParams['axes.linewidth'] = 1 # 图框宽度
plt.rcParams['figure.dpi'] = 150 # plt.show显示分辨率
plt.rcParams['figure.figsize'] = (8,4) # 控制画图的大小
'''
font作用显示相关字体
'''
font = {'family': 'serif',
'serif': 'Times New Roman',
'weight': 'normal',
'size': 10}
plt.rc('font', **font)
data1 = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/MSR-STGCN15minSZ预测.csv',header=None)
data2 = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/MSR-STGCN15minSZ真实.csv',header=None)
y1data = []
y2data = []
y1data = data1.iloc[:, 66] #读取数据 iloc按列读取数据,loc按行读取数据
y2data = data2.iloc[:, 66]
plt.plot( y1data, color='r', mec='r', mfc='w', label=u'MSR-STGCN',zorder=2)#zorder设置顶层突出显示,值越小越在下面
plt.plot(y2data, color='b', mec='r', mfc='w',label=u'Ground Truth',zorder=1) # color可自定义折线颜色,marker可自定义点形状,label为折线标注
# plt.title(u"表名", size=10) #图片的主标题
x = range(0,595)#序列长度
x_ticks_label = ["2015-1-{}".format(i) for i in range(25,32) ] #自定义x轴标签间隔
plt.xticks(x[::96],x_ticks_label[::1]) #时间间隔与标签
# x_major_locator=MultipleLocator(15)#控制x轴刻度间隔以每15显示
# y_major_locator=MultipleLocator(3)#以每3显示
# ax=plt.gca()
# ax.xaxis.set_major_locator(x_major_locator)
# ax.yaxis.set_major_locator(y_major_locator)
plt.legend()#显示图片上线段标签
plt.xlabel(u'Time', labelpad=1,size=10) #x轴标签
plt.ylabel(u'Traffic Speed',labelpad=1, size=10)#y轴标签
plt.savefig("C:/Users/Administrator/Desktop/论文可视化数据/可视化图/最新可视化/SZ粗粒度15min.jpg",bbox_inches='tight',dpi=300)#以多少像素保存
plt.show()
最终画图结果
# -*- coding: utf-8 -*-
# @Time : 2022/9/25 14:37
# @Author : Tiger大队队长
# @File : SZ粗细一起.py
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
font = {'family': 'serif',
'serif': 'Times New Roman',
'weight': 'normal',
'size': 10}
plt.rc('font', **font)
plt.rcParams['font.sans-serif']=['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False # 用来正常显示负号
data1 = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/SZ/MSR-STGCN15minSZ预测.csv',header=None)
data2 = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/SZ/MSR-STGCN15minSZ真实.csv',header=None)
y1data = []
y2data = []
y1data = data1.iloc[:, 66]
y2data = data2.iloc[:, 66]
y3data = []
y4data = []
y3data = data1.iloc[498:594, 66]
y4data = data2.iloc[498:594, 66]
x1 = range(0,595)#序列长度
plt.figure(figsize=(14,6), dpi=300)
plt.figure(1)
ax1 = plt.subplot(211) #图片分割子图 2*1
ax1.plot(x1,y1data, color='r', mec='r', mfc='w', label=u'MSR-STGCN',zorder=2) #zorder表示图层位置,值越大越顶层
ax1.plot(x1,y2data, color='b', mec='r', mfc='w',label=u'Ground Truth',zorder=1)
x_ticks_label = ["2015-1-{}".format(i) for i in range(25,32) ]
ax1.xaxis.set_ticks(x1[::96],x_ticks_label[::1]) #时间间隔与标签
ax1.set_xlabel(u'Time', labelpad=1,size=10)
ax1.set_ylabel(u'Traffic Speed',labelpad=1, size=10)
ax1.legend()#控制图中线条标签
ax1.set_title('(a)',y=-0.3) #y控制标题在下方
ax2 = plt.subplot(212)
y=range(0,96)
x = range(0,96+12)
x_ticks_label = ["0:00","3:00","6:00","9:00","12:00","15:00" ,"18:00","21:00","0:00"]
ax2.plot(y,y3data, color='r', mec='r', mfc='w', label=u'MSR-STGCN')#画图时不加这个y会出现问题
ax2.plot(y,y4data, color='b', mec='r', mfc='w',label=u'Ground Truth') # color可自定义折线颜色,marker可自定义点形状,label为折线标注
ax2.xaxis.set_ticks(x[::12],x_ticks_label[::1]) #自定义x轴标签显示
ax2.set_xlabel(u'Time', labelpad=1,size=10)
ax2.set_ylabel(u'Traffic Speed',labelpad=1, size=10)
ax2.legend()
ax2.set_title('(b)',y=-0.3)
plt.subplots_adjust(hspace=0.3) #控制子图间隔,可有多个参数
plt.savefig("C:/Users/Administrator/Desktop/SZ细粒度15min.jpg",bbox_inches='tight',dpi=300)
plt.show() #画图显示
最终效果
import pandas as pd
import matplotlib.pyplot as plt
# plt.rcParams['axes.linewidth'] = 1 # 图框宽度
plt.rcParams['figure.dpi'] = 300 # plt.show显示分辨率
plt.rcParams['figure.figsize'] = (8,4) # plt.show显示分辨率
font = {'family': 'serif',
'serif': 'Times New Roman',
'weight': 'normal',
'size': 10}
plt.rc('font', **font)
datapre = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/MSR-STGCN15minSZ预测.csv',header=None)
datatrue = pd.read_csv('C:/Users/Administrator/Desktop/论文可视化数据/模型预测结果/MSRSTGCN/MSR-STGCN15minSZ真实.csv',header=None)
for i in range(156):
print(i)
y1data = []
y2data = []
y1data = datapre.iloc[:, i]
y2data = datatrue.iloc[:, i]
print(len(y1data),len(y2data))
x = range(0, 595)
plt.plot(y1data, color='r', mec='r', mfc='w', label=u'MSR-STGCN') #最好加入x轴标签刻度
plt.plot(y2data, color='b', mec='r', mfc='w', label=u'Ground Truth') # color可自定义折线颜色,marker可自定义点形状,label为折线标注
# plt.title(u"表名", size=10)
x_ticks_label = ["2015-1-{}".format(i) for i in range(25, 32)]
plt.xticks(x[::96], x_ticks_label[::1])
# x_major_locator=MultipleLocator(15)#以每15显示
# y_major_locator=MultipleLocator(3)#以每3显示
# ax=plt.gca()
# ax.xaxis.set_major_locator(x_major_locator)
# ax.yaxis.set_major_locator(y_major_locator)
plt.legend()
plt.xlabel(u'Time', labelpad=1, size=10)
plt.ylabel(u'Traffic Speed', labelpad=1, size=10)
plt.savefig("C:/Users/Administrator/Desktop/可视化/"+str(i+1)+".jpg", bbox_inches='tight', dpi=300)
plt.show()
plt.clf() # 没有此语句会重复画图,
频率分布直方图
import pandas as pd
# 导入所需的python包
# libraries & dataset
import seaborn as sns
import matplotlib.pyplot as plt
font = {'family': 'serif',
'serif': 'Times New Roman',
'weight': 'normal',
'size': 6}
plt.rc('font', **font)
# set a grey background (use sns.set_theme() if seaborn version 0.11.0 or above)
sns.set(style="darkgrid")
data1 = pd.read_csv('E:/jklosquchu.csv')
x = data1.loc[1,:]
# 使用distplot函数绘制基础直方图
# 设置bins参数更改bin的个数
fig=sns.distplot(x,hist=True, kde=True, bins=25)
scatter_fig = fig.get_figure()
plt.xlabel('Traffic Speed',fontsize=15) #添加x轴标签,并改变字体
plt.ylabel('Probability',fontsize=15) #添加y轴变浅,并改变字体
scatter_fig.savefig('C:/Users/Administrator/Desktop/真实.jpg', dpi=300)
plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)