介绍
根据数据大小值生成不同色块的颜色值。
代码
`
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
读取数据文件
excel_path = "xx.csv"
data = pd.read_csv(excel_path)
取result
data_12 = data.iloc[:,3]
取targetID
data_y = data.iloc[:,1]
取inputID
data_x = data.iloc[:,0]
初始化矩阵
fdata = np.zeros((70,199))
i = 0
m = 0
for j in range(0,len(data_x)):
#防止13930数组越界
if (len(data_x)-2) == j :
# print("==xxx==",data_x[j],data_x[j+1])
fdata[i][m]= data_12[j]
# print("m",m)
break
#判断是同一个x坐标
elif data_x[j] == data_x[j+1]:
fdata[i][m] = data_12[j]
#判断是一个新x坐标
elif data_x[j] != data_x[j+1]:
i= i+1
m = 0
fdata[i][m] = data_12[j]
# print("im",i,m ,fdata[i][m])
m = m+1
核对数据
print(fdata[0])
print(fdata[1])
print(fdata[2])
print(fdata[69])
plt.matshow(fdata, cmap=plt.get_cmap('RdBu_r'),alpha=0.9) # , alpha=0.3
颜色条
plt.colorbar()
plt.show()
`