Rudolf Adamkovič Personal site


Plotting multiple functions

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(-np.pi, np.pi, 100)

y_sin = np.sin(x)
y_cos = np.cos(x)

fig, ax = plt.subplots()

ax.set_title('Some trigonometric functions.')

ax.set_xlabel(r'\(x\)')
ax.set_xticks([-np.pi, 0, +np.pi])
ax.set_xticklabels([r'\(-\pi\)', '0', r'\(\pi\)'])

ax.set_ylabel(r'\(y\)')
ax.set_yticks([-1, 0, +1])

ax.plot(x, y_sin, label=r'\(y = \sin(x)\)')
ax.plot(x, y_cos, label=r'\(y = \cos(x)\)')

ax.grid()
ax.legend()

fig
svg/4f242b9a-82bf-4cd2-97bd-c705a1fd4e1a

© 2025 Rudolf Adamkovič under GNU General Public License version 3.
Made with Emacs and secret alien technologies of yesteryear.