Untitled
unknown
plain_text
a year ago
562 B
19
Indexable
import matplotlib.pyplot as plt
import numpy as np
# Define the line y = x between 0 and 5
x = np.linspace(0, 5, 100)
y = x
# Create the plot
plt.figure(figsize=(5,5))
plt.plot(x, y, 'k--', label='y = x') # dashed line
# Shade the region above the line
plt.fill_between(x, y, 5, color="lightblue", alpha=0.5)
# Mark the given points
plt.scatter([0,4], [0,4], color="red", zorder=5)
# Formatting
plt.xlim(0,5)
plt.ylim(0,5)
plt.xlabel("x")
plt.ylabel("y")
plt.title("Dashed line through (0,0) and (4,4), shading y > x")
plt.legend()
plt.grid(True)
plt.show()Editor is loading...
Leave a Comment