Matplotlib各种用法

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")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值