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()
相关推荐
竹笋常青9 小时前
《流星落凡尘》
django·numpy
西柚小萌新1 天前
七.numpy模块
numpy
FreedomLeo13 天前
Python数据分析NumPy和pandas(二十三、数据清洗与预处理之五:pandas的分类类型数据)
python·数据分析·numpy·pandas·categoricals·数据分类分析·建模和机器学习
Kalika0-04 天前
NumPy Ndarray学习
python·学习·numpy
上海亚商投顾5 天前
上海亚商投顾:沪指缩量调整 华为概念股午后爆发
numpy
表示这么伤脑筋的题我不会6 天前
请用python写一段训练模型【InsCode AI 创作助手】
python·numpy
緈福的街口8 天前
ValueError: Object arrays cannot be loaded when allow_pickle=False
python·numpy
阿丁小哥8 天前
【Python各个击破】numpy
开发语言·python·numpy
敲代码不忘补水8 天前
Pandas 数据可视化指南:从散点图到面积图的全面展示
python·信息可视化·数据分析·numpy·pandas·matplotlib
人生の三重奏10 天前
numpy——数学运算
开发语言·python·numpy