plot 3D stem

python 复制代码
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import pandas as pd

from matplotlib import cm


width = 3088
height = 2064

def gen_data():


  x = np.linspace(-10, 10,21)
  y = np.linspace(-10, 10, 21)
  z = np.linspace(15, 25, 21)

  X,Y,Z = np.meshgrid(x,y,z)
  coors = np.concatenate((X[:, :, :, None], Y[:, :, :, None], Z[:, :, :, None]), axis=-1)
  pt3ds = 0.01*np.float32(coors).reshape(-1,3)

  data = []
  for pt3d in pt3ds:
    pix_left = reproject2_left(pt3d) #np.float32([[1196.6746,   796.03284]])
    pix_right = reproject2_right(pt3d) # np.float32( [[1125.056 , 1051.7277]])

    pix_left = reproject2_left(pt3d)
    pix_right = reproject2_right(pt3d)

    # 改变x值
    distx = []
    for i in range(11):
      step = i/10
      pl =  pix_left.copy()
      pl[0][0]+=step
      pt3d_c =  triangle3d(pl, pix_right)
      distx.append(1000*np.linalg.norm(pt3d_c-pt3d))


    disty=[]
    for i in range(11):
      step = i / 10
      pl = pix_left.copy()
      pl[0][1] += step
      pt3d_c = triangle3d(pl, pix_right)
      disty.append(1000*np.linalg.norm(pt3d_c - pt3d))

    out = [*pt3d, *pix_left[0], *pix_right[0],  distx[5],  max(distx), disty[5], max(disty), np.linalg.norm(pt3d) ]
    data.append(out)


  df = pd.DataFrame(data)
  df.columns = ['x','y','z', 'xl', 'yl', 'xr', 'yr', 'dist_x0.5', 'dist_x1', 'dist_y0.5', 'dist_y1', 'dist_cam']
  df_filter = df.loc[(df['xl'] >= 0) & (df['yl'] >= 0) & (df['xr'] >= 0) & (df['yr'] >= 0)]
  df_filter.to_csv(r'C:\Users\31408\Desktop\datamat\cube_model_8000.csv', index=False, sep=',')
  return df_filter


def viz_cube3d_effect():
  df = pd.read_csv(r'C:\Users\31408\Desktop\datamat\cube_model_8000.csv')
  df_filter = df.loc[(df['xl'] <= width) & (df['yl'] <= height) & (df['xr'] < width) & (df['yr'] < height)]
  data = np.array(df_filter.values)
  layersz = list(set(data[:, 2]))
  layersz.sort()
  layersz.pop()

  rows, cols = 1, 1
  x = np.linspace(-10, 10, 21) / 100
  y = np.linspace(-10, 10, 21) / 100

  for ii, layerz in enumerate(layersz):
    fig = plt.figure(figsize=(1200, 1000))
    ax = fig.add_subplot(rows, cols, 1, projection='3d')
    ax.set_title(f'z={np.round(layerz, 3)}')
    ax.set_xlabel('x')
    ax.set_ylabel('y')
    vizd = np.float32([item for item in data if item[2] == layerz])
    ax.stem(vizd[:, 0], vizd[:, 1], vizd[:, -5])

    X, Y = np.meshgrid(x, y)
    # R = np.sqrt(X ** 2 + Y ** 2)
    Z = np.ones((21, 21)) * 0.1
    surf = ax.plot_surface(X, Y, Z, cmap='rainbow', linewidth=0, antialiased=False)
    plt.show()


def viz_image_effect():
  df = pd.read_csv(r'C:\Users\31408\Desktop\datamat\cube_model_8000.csv')
  df_filter = df.loc[(df['xl'] <= width) & (df['yl'] <= height) & (df['xr'] < width) & (df['yr'] < height)]
  data = np.array(df_filter.values)

  leftx = data[:,3]
  lefty = data[:,4]
  err = data[:,7]

  fig = plt.figure(figsize=(1200, 1000))
  ax = fig.add_subplot(1, 1, 1, projection='3d')
  ax.set_title(f'left')
  ax.stem(leftx, lefty, err)

  x = np.linspace(0, 3088, 20)
  y = np.linspace(0, 2064, 20)
  X, Y = np.meshgrid( x,  y)
  Z = np.ones((len(X), len(Y))) * 0.1
  surf = ax.plot_surface(X, Y, Z, cmap='rainbow', linewidth=0, antialiased=False)
  plt.show()


viz_cube3d_effect()
相关推荐
敲代码不忘补水1 天前
Python Matplotlib 数据可视化全面解析:选择它的七大理由与入门简介
开发语言·python·信息可视化·numpy·pandas·matplotlib
取个名字真难呐2 天前
2、PyTorch张量的运算API(上)
pytorch·python·numpy
敲代码不忘补水3 天前
pandas 机器学习数据预处理:从缺失值到特征切分的全面解析
人工智能·后端·python·机器学习·numpy·pandas·matplotlib
小青头8 天前
numpy学习笔记
笔记·学习·numpy
取个名字真难呐8 天前
矩阵乘法实现获取第i行,第j列值,矩阵大小不变
python·线性代数·矩阵·numpy
小锋学长生活大爆炸9 天前
【教程】Cupy、Numpy、Torch互相转换
pytorch·numpy·cupy
鱼灯几许10 天前
Python爬虫
爬虫·python·numpy
爱折腾的小码农11 天前
记一次宝塔centos出现Failed to start crond.service: Unit crond.service not found.解决
python·centos·numpy
正义的彬彬侠13 天前
XGBoost算法Python代码实现
python·决策树·机器学习·numpy·集成学习·boosting·xgboost
竹笋常青15 天前
《流星落凡尘》
django·numpy