nishiyamasuの日記

忘れやすいので、メモ。。。

(Python)matplotlibで基本的なグラフをもっと描く

こちらに関連した記事になります。

nishiyamasu.hatenablog.com

今回も、いろんなサンプルを列挙していきます(笑)

 y = x^{2}

import matplotlib.pyplot as plt
import numpy as np

n = 10
x = np.arange(-1*n, n, 0.1)
y = x * x

plt.plot(x, y)
plt.grid()
plt.savefig("parabola1.png")
plt.show()

f:id:nishiyamasu:20220128232034p:plain
parabola1

 y = x^{3}-7x^{2}+5x+1

import matplotlib.pyplot as plt
import numpy as np

n = 4
x = np.arange(-1*n, n, 0.1)
y = x**3 - 7 * x**2 + 5 * x + 1

plt.plot(x, y)
plt.grid()
plt.savefig("parabola1.png")
plt.show()

f:id:nishiyamasu:20220128232944p:plain
cubic_function

 y = 2^{x}  - 10

import matplotlib.pyplot as plt
import numpy as np

n = 10
x = np.arange(-1*n, n, 0.1)
y = 2**x - 10

plt.plot(x, y)
plt.grid()
plt.savefig("2_x.png")
plt.show()

f:id:nishiyamasu:20220128233352p:plain
2_x

 y = \sqrt{x}

import matplotlib.pyplot as plt
import numpy as np

n = 10
x = np.arange(0, n, 0.1)
y = np.sqrt(x)

plt.plot(x, y)
plt.grid()
plt.savefig("sqrt.png")
plt.show()

f:id:nishiyamasu:20220128233700p:plain
sqrt