import numpy as np
import matplotlib.pyplot as plt
x0 = 0.0
y0 = 1.0
#----- derivative coefficient ----
d_y1 = -np.sin(3*x0) - 3*y0
d_y2 = -3*np.cos(3*x0) - 3*d_y1
d_y3 = 3**2*np.sin(3*x0) - 3*d_y2
d_y4 = 3**3*np.cos(3*x0) - 3*d_y3
d_y5 = -3**4*np.sin(3*x0) - 3*d_y4
d_y6 = -3**5*np.cos(3*x0) - 3*d_y5
d_y7 = 3**6*np.sin(3*x0) - 3*d_y6
d_y8 = 3**7*np.cos(3*x0) - 3*d_y7
d_y9 = -3**8*np.sin(3*x0) - 3*d_y8
n = np.arange(0, 41)
x = n/40
h=1/40
#----- precision solution ---
y = (np.cos(3*x) -np.sin(3*x) + 5*np.e**(-3*x))/6
#----- Numerical solution ---
y2 = y0 + (n*h)*d_y1
y5 = y0 + (n*h)*d_y1 + (n*h)**2 * (d_y2/2) + (n*h)**3 * (d_y3/6) + (n*h)**4 * (d_y4/24)
y10 = y0 + (n*h)*d_y1 + (n*h)**2 * (d_y2/2) + (n*h)**3 * (d_y3/6) + (n*h)**4 * (d_y4/24) + (n*h)**5 * (d_y5/120) + (n*h)**6 * (d_y6/720) + (n*h)**7 * (d_y7/5040) + (n*h)**8 * (d_y8/40320) + (n*h)**9 * (d_y9/362880)
print(" x y y2 y5 y10")
for i in n:
print("%6.3f%14.8f%14.8f%14.8f%14.8f" % (x[i], y[i], y2[i], y5[i],y10[i]))
plt.title("Ordinary Differential Equation")
plt.xlabel("x")
plt.ylabel("y")
plt.grid(True)
plt.plot(x, y, label='precision solution')
plt.scatter(x, y2, marker='0', label='Up to item 2')
plt.scatter(x, y5, marker='^', label='Up to item 5')
plt.scatter(x, y10, marker='s', label='Up to item 2')
plt.xlim(0,0.9, 0.1)
plt.ylim(-0.4, 1.2, 0.2)
plt.legend()
plt.show()
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/matplotlib/markers.py", line 305, in set_marker
Path(marker)
File "/usr/local/lib/python3.7/site-packages/matplotlib/path.py", line 132, in __init__
cbook._check_shape((None, 2), vertices=vertices)
File "/usr/local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 2304, in _check_shape
f"{k!r} must be {len(target_shape)}D "
ValueError: 'vertices' must be 2D with shape (M, 2). Your input has shape ().
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "exper11_2.py", line 35, in <module>
plt.scatter(x, y2, marker='0', label='Up to item 2')
File "/usr/local/lib/python3.7/site-packages/matplotlib/pyplot.py", line 2895, in scatter
**({"data": data} if data is not None else {}), **kwargs)
File "/usr/local/lib/python3.7/site-packages/matplotlib/__init__.py", line 1447, in inner
return func(ax, *map(sanitize_sequence, args), **kwargs)
File "/usr/local/lib/python3.7/site-packages/matplotlib/cbook/deprecation.py", line 411, in wrapper
return func(*inner_args, **inner_kwargs)
File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 4473, in scatter
marker_obj = mmarkers.MarkerStyle(marker)
File "/usr/local/lib/python3.7/site-packages/matplotlib/markers.py", line 228, in __init__
self.set_marker(marker)
File "/usr/local/lib/python3.7/site-packages/matplotlib/markers.py", line 309, in set_marker
.format(marker)) from err
ValueError: Unrecognized marker style '0'
エラー原因がわからないです
No.1
- 回答日時:
ぱっと見、問ま題が2つ
①マーカーに '0' は指定できない。'o' のつもりでは?
② xlim, ylim はパラメータ2個の筈(matplotlib 3.6)。
Call signatures::
left, right = xlim() # return the current xlim
xlim((left, right)) # set the xlim to left, right
xlim(left, right) # set the xlim to left, right
bottom, top = ylim() # return the current ylim
ylim((bottom, top)) # set the ylim to bottom, top
ylim(bottom, top) # set the ylim to bottom, top
お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!
関連するカテゴリからQ&Aを探す
おすすめ情報
- ・漫画をレンタルでお得に読める!
- ・人生のプチ美学を教えてください!!
- ・10秒目をつむったら…
- ・あなたの習慣について教えてください!!
- ・牛、豚、鶏、どれか一つ食べられなくなるとしたら?
- ・【大喜利】【投稿~9/18】 おとぎ話『桃太郎』の知られざるエピソード
- ・街中で見かけて「グッときた人」の思い出
- ・「一気に最後まで読んだ」本、教えて下さい!
- ・幼稚園時代「何組」でしたか?
- ・激凹みから立ち直る方法
- ・1つだけ過去を変えられるとしたら?
- ・【あるあるbot連動企画】あるあるbotに投稿したけど採用されなかったあるある募集
- ・【あるあるbot連動企画】フォロワー20万人のアカウントであなたのあるあるを披露してみませんか?
- ・映画のエンドロール観る派?観ない派?
- ・海外旅行から帰ってきたら、まず何を食べる?
- ・誕生日にもらった意外なもの
- ・天使と悪魔選手権
- ・ちょっと先の未来クイズ第2問
- ・【大喜利】【投稿~9/7】 ロボットの住む世界で流行ってる罰ゲームとは?
- ・推しミネラルウォーターはありますか?
- ・都道府県穴埋めゲーム
- ・この人頭いいなと思ったエピソード
- ・準・究極の選択
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Net::SSH::Perlについて
-
メールフォームからメール送信...
-
DBIをCPANからインストール時に...
-
Perlでモジュールを作りましたが、
-
例外処理のフローチャートの記...
-
ユーザー定義関数に#NAME?が返...
-
「デバイスは PRN を初期化でき...
-
VBSがコンパイルエラーになりま...
-
Excel VBAでリンク切れをチェッ...
-
ハマったので助けて~。Apache...
-
Excel VBA 『Call』で呼び出す...
-
Excel VBAで、ユーザーフォーム...
-
別シートに罫線がひけない
-
VHDLにおける「generic」について
-
Movable Type で Hack するため...
-
モジュールとサブルーチン
-
モジュールとクラスの違いって...
-
ImageMagickのインストールにつ...
-
「jcode.pl」というファイルは...
-
印刷後メッセージボックスを表...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Jcode.pmについて
-
Pg.pmモジュールがロードできない
-
Python エクセル読み込み xlrd...
-
cpanからモジュールをインスト...
-
Perl+DBD::Oracleのエラーがわ...
-
YAMLについて
-
python
-
use lib qw(変数名);は無理?
-
@INCにrequireされたファイルが...
-
perlのモジュールについて
-
Expat.soが読めない!?
-
DBIをCPANからインストール時に...
-
ActivePerlに含まれるモジュール
-
ワーニング? encoding.pm
-
XML::Parser::Expat が無い?
-
Pythonの設定方法(text_factory)
-
make 時に標準以外のディレクト...
-
CPAN の初期設定のやり直し方を...
-
vimのvsplit実行時の挙動に関して
-
Perl初心者です このエラーの意...
おすすめ情報