본문 바로가기
대학원 공부/programming language

Matplotlib : 3차원 그래프 그리기

by 월곡동로봇팔 2020. 6. 4.

Data 생성하기

from itertools import product
import numpy as np
from matplotlib import pyplot as plt
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
from sklearn.gaussian_process import GaussianProcessRegressor
from sklearn.gaussian_process.kernels import RBF, ConstantKernel as C

import math

np.random.seed(1)

# ----------------------------------------------------------------------
#  First the noiseless case
X = np.array([[1.50,2],[1.60,2],[1.70,2], [1.80,2], [2.00,2], [2.20, 2], [2.50,2], [2.80,2],[3.00,2], [3.30,2], [3.60,2], [5.00,2], 
              [1.50,1],[1.60,1],[1.70,1], [1.80,1], [2.00,1], [2.20, 1], [2.50,1], [2.80,1],[3.00,1], [3.30,1], [3.60,1], [5.00,1],
              [1.50,3],[1.60,3],[1.70,3], [1.80,3], [2.00,3], [2.20, 3], [2.50,3], [2.80,3],[3.00,3], [3.30,3], [3.60,3], [5.00,3],
              [1.50,4],[1.60,4],[1.70,4], [1.80,4], [2.00,4], [2.20, 4], [2.50,4], [2.80,4],[3.00,4], [3.30,4], [3.60,4], [5.00,4],])
    
print("X shape : ", X.shape)

# Observations
y = np.array(
    [393,405,427,461,502,518,536,552,572,606,646,738,
    364,385,405,431,470,510,526,545,556,589,630,720,
    340,365,395,416,451,495,515,536,549,579,621,708,
    301,320,345,380,418,467,497,510,530,555,600,698])
print("y shape : ", y.shape)


# Input space
x1 = np.linspace(X[:,0].min(), X[:,0].max()) #p
print(x1)
x2 = np.linspace(X[:,1].min(), X[:,1].max()) #q
x = (np.array([x1, x2])).T

kernel = C(1.0, (1e-2, 1e2)) * RBF(100, (1e-3, 1e3))
Exp_kernel = 1.0 * ExpSineSquared(length_scale=1.0, periodicity=3.0,
                                length_scale_bounds=(0.1, 10.0),
                                periodicity_bounds=(1.0, 10.0))
gp = GaussianProcessRegressor(kernel=Exp_kernel, n_restarts_optimizer=15, random_state=1)

gp.fit(X, y)

x1x2 = np.array(list(product(x1, x2)))
y_pred, MSE = gp.predict(x1x2, return_std=True)

X0p, X1p = x1x2[:,0].reshape(50,50), x1x2[:,1].reshape(50,50)
Zp = np.reshape(y_pred,(50,50))

 

3차원 그래프 그리기.

fig = plt.figure(figsize=(10,8))
ax = fig.add_subplot(111)
ax.pcolormesh(X0p, X1p, Zp)
ax = fig.add_subplot(111, projection='3d')            
surf = ax.plot_surface(X0p, X1p, Zp, rstride=1, cstride=1,alpha=0.3, color='blue', cmap='jet',edgecolor='black')
#cmap='jet',
plt.xlabel('$NaBH4$')
plt.ylabel('$PVP$')
plt.show()

 

 

출처 : https://blog.naver.com/PostView.nhn?blogId=badzoo&logNo=221463393938

 

[Anaconda] Python으로 3차원 그래프 그리기

안녕하세요! 오늘은 아나콘다로 3차원 그래프 그리는 방법에 대해 포스팅 하려고 해요.이변수 함수를 그림...

blog.naver.com

https://stackoverflow.com/questions/41572058/how-to-correctly-use-scikit-learns-gaussian-process-for-a-2d-inputs-1d-output

 

How to correctly use scikit-learn's Gaussian Process for a 2D-inputs, 1D-output regression?

Prior to posting I did a lot of searches and found this question which might be exactly my problem. However, I tried what is proposed in the answer but unfortunately this did not fix it, and I coul...

stackoverflow.com

 

댓글