
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を探す
おすすめ情報
デイリーランキングこのカテゴリの人気デイリーQ&Aランキング
-
Perl+DBD::Oracleのエラーがわ...
-
vimのvsplit実行時の挙動に関して
-
例外処理のフローチャートの記...
-
【vba】フォームに書いてあ...
-
「デバイスは PRN を初期化でき...
-
Excel VBAでリンク切れをチェッ...
-
ユーザー定義関数に#NAME?が返...
-
VBでグローバル変数を宣言するには
-
VBAで別モジュールへの変数の受...
-
MS-Access と接続する方法を教...
-
モジュールを使わないで画像サ...
-
fetchrow_arrayとfetchrow_hash...
-
エクセルVBAでシートモジュール...
-
perl起動方法
-
cobol サブルーチンのlink
-
本当にPublicな変数(配列で)
-
Excel VBA 定義されたプロージ...
-
ラズパイ CSV 定量削除
-
Cpanのインストールができません。
-
Oracleのデータベースに接続で...
マンスリーランキングこのカテゴリの人気マンスリーQ&Aランキング
-
Compress:Zlibコンパイルエラー
-
SOAP::Liteを利用したい!
-
perlのモジュールについて
-
perl MeCab 和布蕪 エラー
-
python 環境構築について
-
python
-
use lib qw(変数名);は無理?
-
Perl+DBD::Oracleのエラーがわ...
-
XML::Parser::Expat が無い?
-
Expat.soが読めない!?
-
perl DBD::Pg インストールでエ...
-
Jcode.pmについて
-
Pg.pmモジュールがロードできない
-
CygwinでPerlのCSV_XSを実行する
-
GLIBC_2.4 以上がインストール...
-
Net::SSH::Perlについて
-
DB_Fileモジュールインストール...
-
例外処理のフローチャートの記...
-
Excel VBAでリンク切れをチェッ...
-
Excel VBAで、ユーザーフォーム...
おすすめ情報