LoginSignup
0
2

More than 3 years have passed since last update.

3Dグラフのインタラクティブなプロット

Last updated at Posted at 2020-09-15

Jupyter Notebookでインタラクティブなプロット

シンプルな例を見つけられなかったので、メモとして作成。

詳細な説明やセットアップは下記を参照のこと。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from ipywidgets import interact, FloatSlider, IntSlider
import numpy as np

x = y = np.arange(-20, 20, 0.5)
X, Y = np.meshgrid(x, y)
Z = X*X + 2 * Y*Y


@interact(elev=IntSlider(min=-180, max=180, step=10, value=30, continuous_update=False), 
          azim=IntSlider(min=-180, max=180, step=10, value=30, continuous_update=False))
def plot_3d(elev, azim):
    # Figureの設定
    fig = plt.figure(figsize=(10, 10))

    ax = fig.add_subplot(111, projection='3d')
    # 3Dグラフを表示
    ax.plot_surface(X, Y, Z)

    # 3Dグラフの見る方向の初期値を設定
    ax.view_init(elev=elev, azim=azim)
    plt.show()

image.png

0
2
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
2