#author("2018-02-06T11:04:48+09:00","default:Miyashita","Miyashita") #author("2018-07-25T23:22:10+09:00","default:Miyashita","Miyashita") *Python演習問題:等高線図とベクトル図 [#wb10cce6] ***インポート・エイリアス設定 [#ec330942] いつも通り. import numpy as np import matplotlib.pyplot as plt #codeprettify(lang-python){{ import numpy as np import matplotlib.pyplot as plt }} ***問題 [#edce4580] +[[最大値・最小値の検出>../演習:最大値・最小値の検出]]で作成したpeaksをimportしなさい.importの際に不要な処理をしないよう,peaksが入ったファイルを修正しなさい. from XXX import peaks if __name__ == '__main__': #codeprettify(lang-python){{ from XXX import peaks if __name__ == '__main__': }} +peaksを使って等高線図(コンター)を作成しなさい.座標軸の名前を表示しなさい. #オブジェクト指向らしく fig = plt.figure() ax = fig.add_subplot(111) ax.contour() ax.set_xlael() ax.set_ylabel() # MATLABっぽく plt.contour() plt.xlabel() plt.ylabel() #codeprettify(lang-python){{ #オブジェクト指向らしく fig = plt.figure() ax = fig.add_subplot(111) ax.contour() ax.set_xlael() ax.set_ylabel() # MATLABっぽく plt.contour() plt.xlabel() plt.ylabel() }} +上記のデータから勾配を求め,等高線図の上にオーバーラップさせたベクトル図を作成しなさい.その際に,縦軸,横軸のスケールを1対1としなさい. Fx, Fy = np.gradient(F) # オブジェクト指向らしく ax.quiver(...) ax.quiverkey(...) ax.axis(...) # MATLABっぽく plt.quiver(...) plt_quiverkey(...,labelpos='E') plt.axis(...) #codeprettify(lang-python){{ Fx, Fy = np.gradient(F) # オブジェクト指向らしく ax.quiver(...) ax.quiverkey(...) ax.axis(...) # MATLABっぽく plt.quiver(...) plt_quiverkey(...,labelpos='E') plt.axis(...) }} +peaksを使って塗り潰しコンター図を作成しなさい.コンターの最大値と最小値は[-5,10]で,図の脇にcolorbarを付けなさい.その際にaの2回微分を求め,ベクトル図をオーバーラップさせなさい. C = ax.contourf(xxx,extend='both') Q = ax.quiver(xxx) ax.quiverkey(Q,...) fig.colorbar(C,...) #codeprettify(lang-python){{ C = ax.contourf(xxx,extend='both') Q = ax.quiver(xxx) ax.quiverkey(Q,...) fig.colorbar(C,...) }} +3,4の図をpng,eps形式で保存し,ファイルの大きさを比べなさい. fig.savefig('filename',format='hoge',dpi=num) plt.savefig('filename',format='hoge',dpi=num) #codeprettify(lang-python){{ fig.savefig('filename',format='hoge',dpi=num) plt.savefig('filename',format='hoge',dpi=num) }} ***解答例(参考) [#te606a72] 塗りつぶしコンターは微妙な見栄え.~ &ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/image/python/contour_and_quiver.png,480x360); &ref(https://main-t-miyashita.ssl-lolipop.jp/hydrocoast/image/python/contourf_test.png,480x360);