import seaborn as sns
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import matplotlib as mpl
import matplotlib.ticker as ticker
# plt.style.use('classic')
df = pd.read_csv("./22km.csv")
mpl.rc('image', cmap='jet')
def read_data(name, datas):
data = datas[name]
last_d = data[0]
for i in range(1, data.size):
if (data[i] == data[i]):
last_d = data[i]
else:
data[i] = last_d
return data
vel_x = read_data("/265_camera/odom/sample/twist/twist/linear/x", df)
vel_y = read_data("/265_camera/odom/sample/twist/twist/linear/y", df)
vel_z = read_data("/265_camera/odom/sample/twist/twist/linear/z", df)
pos_x = -read_data("/265_camera/odom/sample/pose/pose/position/x", df)
pos_y = read_data("/265_camera/odom/sample/pose/pose/position/y", df)
pos_z = read_data("/265_camera/odom/sample/pose/pose/position/z", df)
ts = read_data("__time", df)
vel_n = np.sqrt(vel_x ** 2 + vel_y ** 2 + vel_z ** 2)
vel_n = np.around(vel_n,2)
vel_max = np.max(vel_n)
cs = np.zeros((ts.size,4))
viridis = cm.get_cmap('jet', 8)
idxs = np.zeros(ts.size)
vels = np.zeros(ts.size)
def fmt1(x,pos): # 设置colorbar的刻度值
return int(x*6.05)
last_vel = 0;
for i in range(0,ts.size):
# vel = vel_n[i]/vel_max
vel = np.around(vel_n[i]/vel_max,2)
# if(vel == 0):
# vel = last_vel
# else:
# last_vel = last_vel
#
# idx = np.where(colors[:, 0] == vel)
# print( cs[i])
# if(idx[0].size == 0):
# continue
#
# idxs[i] = idx[0][0]
# vels[i] = vel
cs[i] = viridis(vel)
# print(cs[i])
# print("vel =", vel, vel_max)
# print(vel,idx)
# print(idx[0][0])
# plt.plot(ts,vels)
# print(cs.shape)
fig = plt.figure(figsize=(9,5))
plt.scatter(pos_x, pos_y,color = cs,linewidths=0.1 ,s = 12.3)
cbar= plt.colorbar(fraction=0.03, pad=0.05, format=ticker.FuncFormatter(fmt1), )
cbar.set_label('Norm of velocity (m/s)',loc='center')
# plt.axis("equal")
plt.xlim(-5,70)
plt.ylim(-1,3)
plt.xlabel("Position x (m)")
plt.ylabel("Position y (m)")
plt.savefig("pos_vel.svg")
Matplotlib各种用法
最新推荐文章于 2024-08-23 16:53:34 发布