Preview:
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()
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter