python-三维数据显示

# -*- coding: utf-8 -*-
"""
Created on Tue Aug 21 10:07:20 2018

@author: zhoubo
"""
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
from scipy.optimize import curve_fit
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler

data = pd.read_csv('D:/xxx/data/rgbData.csv', header=None)
#print(data)
# get the rgb value
rgbR = data.loc[1:,0:0].values
rgbR = list(map(int, rgbR))

rgbG = data.loc[1:, 1:1].values
rgbG = list(map(int, rgbG))

rgbB = data.loc[1:, 2:2].values
rgbB = list(map(int, rgbB))

indexBg   = rgbR.index(-3)
indexUk   = rgbR.index(-2) + 1
indexFg   = rgbR.index(-1)

fig = plt.figure(figsize=(10, 10))
plane = Axes3D(fig)
#bg
plane.scatter(rgbR[1:indexBg], rgbG[1:indexBg], rgbB[1:indexBg], 
           c='blue', alpha=0.5, marker='o', label='bg-fg', s =10)  
#unknown
#plane.scatter(rgbR[indexBg:indexUk], rgbG[indexBg:indexUk], 
#           rgbB[indexBg:indexUk], c='y', alpha=1, marker='^', label='bg-fg') 
#fg
plane.scatter(rgbR[indexUk:indexFg], rgbG[indexUk:indexFg], 
           rgbB[indexUk:indexFg], c='black', alpha=1, marker='o', label='bg-fg', s = 10)
 
plane.set_xlabel('r')
plane.set_ylabel('g')
plane.set_zlabel('b')  # 坐标轴

plane.view_init(elev=60, azim=40)
#plt.show()

#dataAlphafg = pd.read_csv('C:/Users/zhoubo/Desktop/data/alphaData.csv', header=None)
#fgalphaValue = dataAlphafg.loc[0:, 0:0].values 
#fgalphaValue = list(map(int, fgalphaValue))
#
#fgDis = dataAlphafg.loc[0:, 1:1].values
#fgDis = list(map(int, fgDis)) 

#plt.figure(figsize=(10, 10))
#alphaDraw = plt.subplot(221) 
#x = list(range(len(fgalphaValue)))
#alphaDraw.scatter(x, fgalphaValue[0:len(fgalphaValue)],  c='#00ff00', alpha=1, marker='o', label='alpha', s =50)
#alphaDraw.set_xlabel('num')
#alphaDraw.set_ylabel('alpha')
#
#alphaHist = plt.subplot(222)
#num_bins = 256 
#alphaHist.hist(fgalphaValue, num_bins, facecolor='red')
#alphaHist.set_title('alpha frequency',fontsize=12,color='r')
#
#disHist = plt.subplot(223)
#disHist.hist(fgDis, num_bins, facecolor='purple')
#disHist.set_title('distance to param plane',fontsize=12,color='r')
#
#vio = plt.subplot(224)
#vio.violinplot(fgalphaValue)
#vio.set_title('feature distribution')

fgFitR =  rgbR[indexUk + 1:indexFg];#indexUk:indexFg
fgFitG =  rgbG[indexUk + 1:indexFg];
fgFitB =  rgbB[indexUk + 1:indexFg];
#
#plane.plot_trisurf(fgFitR, fgFitG, fgFitB, alpha = 0.5)

lineFitR =  rgbR[indexBg + 1:indexUk];#indexUk:indexFg
lineFitG =  rgbG[indexBg + 1:indexUk];
lineFitB =  rgbB[indexBg + 1:indexUk];

#lineFitR.insert(0, rgbR[indexBg//2])
#lineFitG.insert(0, rgbG[indexBg//2])
#lineFitB.insert(0, rgbB[indexBg//2])
centerBg = indexBg // 2
bgSource = [rgbR[centerBg], rgbG[centerBg], rgbB[centerBg]]
#for  i in range(0, len(lineFitR), 5):
#   linePairR = [bgSource[0], lineFitR[i]]
#   linePairG = [bgSource[1], lineFitG[i]]
#   linePairB = [bgSource[2], lineFitB[i]]
#   plane.plot(linePairR[0:2], linePairG[0:2], linePairB[0:2]) 
   

fitpara = data.loc[0:0, 3:8].values
#fitpara = list(map(float, fitpara))
fitpara1 = fitpara.tolist()
strfit   = str(fitpara1)
strfit = strfit.replace('[','')
strfit = strfit.replace(']','')
#最后转化成列表
fitpara = list(eval(strfit))

x = np.arange(0, 256, 1)
y = np.arange(0, 256, 1)
X , Y = np.meshgrid(x, y)
Z =    fitpara[0] + fitpara[1] * X + fitpara[2] * Y + fitpara[3] * X * X  \
     + fitpara[4] * X * Y + fitpara[5] * Y * Y
plane.plot_surface(X, Y, Z, rstride=5, cstride=5, cmap=plt.cm.coolwarm,alpha=0.8) 

plane.set_zlim3d(0,256)

plt.show()

python-三维数据显示_第1张图片

你可能感兴趣的:(python,图像处理)