matplotlib

matplotlib で、2次関数のグラフを描画する方法

投稿日:

2次関数のグラフを表示するには次のようにする。

import matplotlib.pyplot as plt
import numpy as np

# numpy linspace 等間隔な数列を生成する
x_1 = np.linspace(-5,5,20)

# 関数
y_1 = 2 * x_1 ** 2 - 3

# プロット
plt.plot(x_1,y_1)

# タイトルを表示する
plt.title('TITLE')

# プロットを画面に表示する
plt.show()

結果

-matplotlib
-,

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

matplotlib で、矢印を描く方法

arrowprops のパラメータは次を参考にして設定できる。 https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.FancyAr …

no image

matplotlib で、凡例を表示する位置を変更する方法

凡例(legend)の表示位置を変更するには、axis の legend の loc を設定する。 次のリンクhttps://matplotlib.org/stable/api/_as_gen/mat …

no image

matplotlib で、グラフの点の見た目を変更する方法

「marker」で指定すればよい。 次のページを参考に、plotの「marker」を変更する。 https://matplotlib.org/stable/api/markers_api.html 例 …

no image

matplotlib で、x軸・y軸の目盛りを反対方向につけたい場合。

デフォルトでは、x軸はグラフの下に、y軸は左側につけられる。 例 import numpy as np from matplotlib import pyplot as plt x = np.lins …

no image

matplotlib でcsv ファイルを読み込むとき、最初の行をスキップする方法

numpy の loadtxt で読み込む行を省略したい場合 スキップしたい行を # 等の記号でコメントアウトして、 loadtxt の comments = ‘#’ とすると …