4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

numpy と matplotlib で三角関数をグラフで表示

Last updated at Posted at 2017-08-05

数式を簡単に扱うモジュールとグラフに変換できるモジュールをインポートします。

import matplotlib.pyplot as plt

サイン、コサイン、タンジェントの表示

x = plt.linspace(-np.pi,np.pi) # グラフの横表示の指定
plt.plot(x, np.cos(x), color='r', ls='-', label='cos') # コサインの表示
plt.plot(x, np.sin(x), color='b', ls='-', label='sin') # サインの表示
plt.plot(x, np.tan(x), color='c', marker='s', ls='None', label='tan') # タンジェントの表示

グラフの縦横表示指定

plt.xlim(-np.pi, np.pi)
plt.ylim(-1.5, 1.5)```

<strong>グラフの縦横表示指定</strong>
```plt.axhline(0, ls='-', c='b', lw=0.5)
plt.axvline(0, ls='-', c='b', lw=0.5)```

<strong>グラフの縦横表示指定</strong>
```plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.title('Graphs')
plt.show()```

<h1>全コード</h1>

```Main.py
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-np.pi, np.pi)
plt.plot(x, np.cos(x), color='r', ls='-', label='cos')
plt.plot(x, np.sin(x), color='b', ls='-', label='sin')
plt.plot(x, np.tan(x), color='c', marker='s', ls='None', label='tan')

plt.xlim(-np.pi, np.pi)
plt.ylim(-1.5, 1.5)

plt.axhline(0, ls='-', c='b', lw=0.5)
plt.axvline(0, ls='-', c='b', lw=0.5)

plt.legend()
plt.xlabel('x')
plt.ylabel('y')
plt.title('Graphs')

plt.show()

表示
download-1.png

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?