質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

1回答

2820閲覧

matplotlibについて

dddaaa

総合スコア12

Matplotlib

MatplotlibはPythonのおよび、NumPy用のグラフ描画ライブラリです。多くの場合、IPythonと連携して使われます。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2019/01/06 06:08

前提・実現したいこと

matplotlibでグラフをいくつも書くプログラムを作成中なのですが、このような警告文が出てきました. plt.closeやplt.clfを使えば良いのでしょうか?詳しく教えていただきたいです.よろしくお願い致します.

発生している問題・エラーメッセージ

RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`). max_open_warning, RuntimeWarning)

Python(jupiter notebook)

import numpy as np import matplotlib.pyplot as plt import matplotlib.animation as animation #====== FIgures ========== wa = 2000 # (kN/m) wb = 500 a = 5.0 # (m) b = 0 #====== Values of Cross section ======== b=6.0 #width(m) h=2.0 #height(m) E=3.0*(10**7) #Elastic Coefficient(kN/m2) d=1.8 #Valid height (m) As=20270.0/(10**6) #Area of steel bar(m2)D51 10bars n=7.0 #Ratio of Es to Ec Ac=b*h+n*As #Area of simulated cross section yc=(b*h*h/2)+(n*As*d) #distanse from above to neutral axis Ic=((h**3)*b/12)+(b*h*((h/2-yc)**2))+(n*As*((d-yc)**2)) #Moment of inertia #====== Structural Dimension =========== l = 50 #span length(m) l1= 0 l2 = l - l1 - a while l1<50: fig = plt.figure() ims = [] x1=np.arange(0, l1, 0.1) x2=np.arange(0, a, 0.1) x3=np.arange(0, l2, 0.1) #=== Reaction Force ========= Va=wa*a-(wa*a*(0.5*a + l1))/l Vb=(wa*a*(l1 + 0.5*a))/l #=== Constant Value ========= E1=-(-3*wa*(a**4)/24 + Va*(a**3)/3 + Va*l1*a*a - wa*(a**3)*l1/6 + Va*l1*l1*a + Va*(l1**3)/3 + wa*(a**2)*(l2**2)/4 + wa*a*(l2**3)/6 - Va*l1*l2*l2/2 - Va*l2*l2*a/2 - Va*(l2**3)/6)/l E2=-(wa*(a**2)*(l2**2)/4 + wa*a*(l2**3)/6 - Va*l1*l2*l2/2 - Va*a*l2*l2/2 - Va*(l2**3)/6 + E1*l2) D1=E1-(wa*(a**3)/6 - Va*a*a/2 - Va*l1*a) C1=D1+(Va*(l1**2)/2) D2=C1*l1 - Va*(l1**3)/6 #=== Ordinary Differential Equation ====== U12=(-Va*(x1**3)/6 + C1*x1)/E/Ic U23=(wa*((x2)**4)/24 - Va*((x2)**3)/6 -Va*l1*((x2)**2)/2 + D1*(x2) + D2)/E/Ic U34=(wa*a*a*((x3)**2)/4 + wa*a*((x3)**3)/6 - Va*l1*((x3)**2)/2 - Va*a*((x3)**2)/2 - Va*((x3)**3)/6 + E1*(x3) + E2)/E/Ic #x軸の座標移動のため nn=x2+l1 xx=x3+a+l1 l1 += 0.1 if l1+a >50: l2= 0 a = l - l1 if a < 0: a = 0 im = plt.plot(x1,U12 , color = "yellow") im1 =plt.plot(nn, U23 , color = "yellow") im2 = plt.plot(xx, U34 , color = "yellow") ims.append(im + im1 + im2) ani = animation.ArtistAnimation(fig, ims, interval = 30 ) plt.show() fig.clf()

試したこと

ここに問題に対して試したことを記載してください。

補足情報(FW/ツールのバージョンなど)

ここにより詳細な情報を記載してください。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

質問にあるコードで試したところ、質問者さんの場合より少し長めの警告文が出ました。

More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_open_warning`).

これを翻訳すると以下の通り。

20以上の数字が開かれています。 pyplotインターフェース( matplotlib.pyplot.figure)を通して作成されたFigureは明示的に閉じられるまで保持され、メモリを消費しすぎるかもしれません。 (この警告を制御するには、rcParamの figure.max_open_warningを参照してください)。

「figure.max_open_warning」でいろいろ調べてみることをおすすめします。

plt.closeやplt.clfを使えば良いのでしょうか?

軽く調べましたが、多分それであっています。

投稿2019/04/22 15:34

amahara_waya

総合スコア1029

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問