Rudolf Adamkovič Personal site


Plotting single function

To plot a function in Matplotlib:

import matplotlib.pyplot as plt
import numpy as np

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

fig, ax = plt.subplots()

ax.grid()

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 = \sin(x)\)')
ax.set_yticks([-1, 0, +1])
ax.set_title('The sine function.')

ax.plot(x, y)

fig
svg/61bd589a-915c-4a34-a540-69f6183e1fe7

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