Line Graph – A chart that visualizes data in the form of data points connected by straight lines, used to track the trend of data fluctuations over time or another continuous interval.
Draw a line graph:
import matplotlib.pyplot as plt
# Data
x = [1, 2, 3, 4, 5]
y1 = [10, 20, 15, 25, 30] # First line (original)
y2 = [12, 18, 22, 28, 35] # Second line (green)
y3 = [8, 15, 13, 20, 25] # Third line (red)
# Plot line charts
plt.plot(x, y1, marker='o', label='Line 1 (Blue)', color='blue') # Circle marker at each point
plt.plot(x, y2, marker='s', label='Line 2 (Green)', color='green') # Square marker
plt.plot(x, y3, marker='^', label='Line 3 (Red)', color='red') # Triangle marker
# Add title and axis labels
plt.title('Simple Line Chart')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
# Show grid (optional)
plt.grid(True)
# Show legend
plt.legend()
# Display the chart
plt.show()
Output:
