Matplotlib Plotting 📈
Plotting Basics
The plot() function is versatile. It can draw lines, points, or both, depending on the arguments you provide.
✨ Plotting Without Lines
To plot only markers (like a scatter plot), use a shortcut string like 'o' (rings) as the third argument.
python
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 8])
y = np.array([3, 10])
plt.plot(x, y, 'o') # 'o' means rings
plt.show()🔢 Multiple Points
You can plot as many points as you like.
python
x = np.array([1, 2, 6, 8])
y = np.array([3, 8, 1, 10])
plt.plot(x, y)
plt.show()📉 Default X-Points
If you omit the X points, Matplotlib automatically uses indices 0, 1, 2, 3....
python
y = np.array([3, 8, 1, 10, 5, 7])
plt.plot(y)
# X-values will be: [0, 1, 2, 3, 4, 5]
plt.show()✨ Pro Tip
You can plot multiple lines in a single plot() call by repeating the x, y pairs:
python
plt.plot(x1, y1, x2, y2)