gnuplotの様に,ある関数を画面出力する.


In [1]:
%matplotlib inline
import numpy as np

In [2]:
def func1(x):
    y = 1/(1+np.exp(-x))
    return y

In [3]:
def func2(x):
    y = x**2
    return y

In [4]:
def func3(x):
    y = np.sin(x)
    return y

In [5]:
import matplotlib.pyplot as plt

# 定義域を設定
xmin = -10.0
xmax = 10.0
num = 100 # xminからxmaxまでをnum個で区切る
x = np.linspace(xmin, xmax, num)

# 関数から値域を取得
#y = func1(x)
#y = func2(x)
y = func3(x)

# 点どうしを直線でつなぐ
plt.plot(x, y)

# 適切な表示範囲を指定
plt.xlim(xmin, xmax)

# グリッド追加
plt.grid(True)

# 表示
plt.show()


3次元プロット


In [1]:
%matplotlib inline

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(-3, 3, 0.25)
y = np.arange(-3, 3, 0.25)
X, Y = np.meshgrid(x, y)
Z = 6*X*X + 4*X*Y + 3*Y*Y

fig = plt.figure()
ax = Axes3D(fig)
ax.plot_wireframe(X,Y,Z) 

plt.show()


/usr/local/lib/python3.5/site-packages/matplotlib/collections.py:590: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison
  if self._edgecolors == str('face'):

In [ ]: