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()
相关推荐
南宫理的日知录2 小时前
「Python数据科学」标量、向量、矩阵、张量与多维数组的辨析
python·numpy·数据科学
ROBOT玲玉1 天前
Milvus 中,FieldSchema 的 dim 参数和索引参数中的 “nlist“ 的区别
python·机器学习·numpy
GocNeverGiveUp1 天前
机器学习2-NumPy
人工智能·机器学习·numpy
AI小白白猫2 天前
20241230 基础数学-线性代数-(1)求解特征值(numpy, scipy)
线性代数·numpy·scipy
子晓聊技术6 天前
【Python技术】同花顺wencai涨停分析基础上增加连板分析
后端·python·numpy
西猫雷婶9 天前
python学opencv|读取图像(九)用numpy创建黑白相间灰度图
python·opencv·numpy
星霜旅人9 天前
Python的基础知识
开发语言·python·numpy
fmc12110411 天前
【3】数据分析基础(Numpy的计算)
数据挖掘·数据分析·numpy
HP-Patience11 天前
【NumPy进阶】:内存视图、性能优化与高级线性代数
python·numpy
sinat_3842410913 天前
Python程序是一个基于Tkinter的GUI应用程序,用于录制和回放用户的鼠标和键盘操作
python·django·flask·beautifulsoup·numpy·scikit-learn