Graph trigonometric functions with numpy and matplotlib

Import modules that handle formulas easily and modules that can be converted into graphs. </ strong>

import matplotlib.pyplot as plt

Sine, cosine, tangent display </ strong>

x = plt.linspace(-np.pi,np.pi) #Specifying the horizontal display of the graph


plt.plot(x, np.cos(x), color='r', ls='-', label='cos') #Display of cosine
plt.plot(x, np.sin(x), color='b', ls='-', label='sin') #Display of sign
plt.plot(x, np.tan(x), color='c', marker='s', ls='None', label='tan') #Display of tangent

Graph vertical / horizontal display specification </ strong>

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


plt.ylim(-1.5, 1.5)```

 <strong> Graph vertical / horizontal display specification </ strong>

#### **`plt.axhline(0, ls='-', c='b', lw=0.5)`**

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

Graph vertical / horizontal display specification </ strong>

plt.legend()


plt.xlabel('x')
plt.ylabel('y')
plt.title('Graphs')
plt.show()```

 <h1> All codes </ h1>


#### **`Main.py`**
```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()

Display </ strong> download-1.png

Recommended Posts