前提
google colaboratoryで matplotlib 3d surface のアスペクト比を変更したいのですが、Jupiter notebookで上手くいくコードがなぜかエラーを吐いてしまいます。ご教示いただけないでしょうか。よろしくお願い致します。
実現したいこと
google colaboratoryでmatplotlib 3d surface のアスペクト比を変更したい
発生している問題・エラーメッセージ
matplotlib 3d のアスペクト比を変更するためset_box_aspect()
を使用してみた。
結果、Jupiter notebookでは上手くアスペクト比を変更できたのに対し、google colaboratoryではエラーとなった。
以下、google colaboratoryでset_box_aspect()
を使用した際のエラーメッセージ
'Axes3DSubplot' object has no attribute 'set_box_aspect'
該当のソースコード
Python
1!pip install matplotlib==3.3 2from mpl_toolkits.mplot3d import Axes3D 3import matplotlib.pyplot as plt 4from matplotlib import cm 5from matplotlib.colors import LightSource 6import numpy as np 7 8x = np.arange(100) 9y = np.arange(200) 10x, y = np.meshgrid(x, y) 11z = np.sin(x + y) 12xmin,xmax = 0,100 13ymin,ymax = 0,200 14zmin,zmax = int(np.round(np.min(z))),int(np.round(np.max(z))) 15 16fig = plt.figure() 17ax = fig.add_subplot(projection='3d') 18ax.plot_surface(x, y, z) 19ax.view_init(elev=90, azim=90) 20ax.set_box_aspect((xmax-xmin,ymax-ymin,zmax-zmin)) 21ax.set_xlim3d(xmin, xmax) 22ax.set_ylim3d(ymin, ymax) 23ax.set_zlim3d(zmin, zmax)
試したこと
Jupiter notebookで該当のソースコードと全く同じコードを入力し、実行してみたところ上手くアスペクト比が変更された。(google colaboratoryのようなエラーが発生しなかった。)
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。