Let’s draw again. This time we will use a matplotlib and numpy to get python cos(x) graph.
Draw a cos(x)
I have prepared a code which I am pasting below.
You need to import both matplotlib and numpy.
import matplotlib.pyplot as plt import numpy as np fig = plt.figure() ax = fig.add_subplot(111) x_min = -5.0 x_max = 5.0 y_min = -1.5 y_max = 1.5 x = np.arange(x_min, x_max, 0.10) y = np.cos(x) plt.xlim(x_min, x_max) plt.ylim(y_min, y_max) plt.plot(x, y) grid_x_ticks_minor = np.arange(x_min, x_max, 0.25 ) grid_x_ticks_major = np.arange(x_min, x_max, 0.50 ) ax.set_xticks(grid_x_ticks_minor, minor = True) ax.set_xticks(grid_x_ticks_major) grid_y_ticks_minor = np.arange(y_min, y_max, 0.5) grid_y_ticks_major = np.arange(y_min, y_max, 1.0) ax.set_yticks(grid_y_ticks_minor, minor = True) ax.set_yticks(grid_y_ticks_major) ax.grid(True, which='minor', alpha=0.25, color = 'b') plt.title('cosine(x)') plt.show()