0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

pythonでグラフ描く度に調べてるので、最もシンプルな使い方だけまとめとく

Last updated at Posted at 2021-01-14

pythonでグラフ描く度に調べてるので、最もシンプルな使い方だけまとめとく

jupyter notebook使ってます。
jupyter notebookじゃないのなら「%matplotlib inline」は不要

2次元グラフ


# ライブラリのインポート
%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np

# グラフ描画したい関数
def func(x):
    return x**2

# 変数準備
# np.arange(開始, 終了, ステップ)
x = np.arange(0.0, 10.0, 0.1)
y = func(x)

# グラフに描画
plt.plot(x, y);

2d.png

3次元グラフ


# ライブラリのインポート
%matplotlib inline
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

# グラフ描画したい関数
def func(x, y):
    return x * y * (10 - x - y)

# 変数準備
x = np.arange(0.0, 10.0, 0.1)
y = np.arange(0.0, 10.0, 0.1)
X, Y = np.meshgrid(x, y)
Z = func(X, Y)

# 描画
fig = plt.figure()
ax = Axes3D(fig)
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("f(x, y)")
ax.plot_wireframe(X, Y, Z)
plt.show()

3d.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?