매트랩에 비해 많이 불편하다. ㅠㅠ 이래서 매트랩을 쓰게 되는 듯...
import numpy as np
from scipy import interpolate
import matplotlib.pyplot as plt
X = np.linspace(0,10,10)
Y = np.sin(X)
X1 = np.linspace(0,10,100)
f1 = interpolate.interp1d(X,Y,'linear')
f2 = interpolate.interp1d(X,Y,'cubic')
f3 = interpolate.interp1d(X,Y,'quadratic')
Y1 = f1(X1)
Y2 = f2(X1)
Y3 = f3(X1)
Y4 = np.sin(X1)
plt.plot(X,Y,'o', X1,Y1, X1,Y2, X1,Y3, X1,Y4)
plt.legend(['sin','linear','cubic','quadratic','sin'])
plt.show()
X = np.linspace(-10,10,20)
[Xmg,Ymg] = np.meshgrid(X,X)
Rmg = (Xmg**2 + Ymg**2)**0.5
Zmg = np.cos(Rmg)
fig = plt.figure()
# fig = plt.figure(figsize=(14,9))
ax = plt.axes(projection='3d')
ax.plot_surface(Xmg,Ymg,Zmg)
ax.set_zlim(-1.5, 1.5)
plt.show()
X1 = np.linspace(-10,10,200)
Y1 = X1
[X1mg,Y1mg] = np.meshgrid(X1,X1)
f1 = interpolate.interp2d(Xmg,Ymg,Zmg, kind='cubic')
Z1a = f1(X1,Y1) # arguments have to be 1D not like Matlab
fig = plt.figure()
ax = plt.axes(projection='3d')
ax.plot_surface(X1mg,Y1mg,Z1a)\
ax.set_zlim(-1.5, 1.5)
plt.show()
'Coding > Python Matlab' 카테고리의 다른 글
Matlab - ginput() get coordinate on the plot by mouse click (0) | 2022.11.30 |
---|---|
Matlab - bmp_to_data() (0) | 2022.11.12 |
python subprocess, time delay, current working directory (0) | 2022.09.25 |
matlab 2 y axes overlaid plots (0) | 2022.09.08 |
Matlab 과 Python 에서 multidimensional array 차이 (0) | 2022.08.27 |