code to produce a 'straight line'

PHOTO EMBED

Tue Nov 14 2023 20:08:08 GMT+0000 (Coordinated Universal Time)

Saved by @dr_dziedzorm

import matplotlib.pyplot as plt
import numpy as np

# Parameters for the line
slope = 1  # Slope of the line, m
intercept = 0  # Y-intercept of the line, c

# Create a range of x values
x_values = np.linspace(start=-10, stop=10, num=100)

# Calculate the y values based on the slope and intercept
y_values = slope * x_values + intercept

# Plotting the line
plt.figure(figsize=(8, 6))
plt.plot(x_values, y_values, '-r', label=f'y = {slope}*x + {intercept}')
plt.title('Graph of a Straight Line')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.grid(True)
plt.show()
content_copyCOPY