Introduction
We use plt.plot to draw simple line graphs. It helps us see how numbers change over time or compare values.
We use plt.plot to draw simple line graphs. It helps us see how numbers change over time or compare values.
plt.plot(x, y, format_string, **kwargs) plt.show()
x and y are lists or arrays of numbers.
format_string is optional and controls line style and color.
plt.plot([1, 2, 3], [4, 5, 6]) plt.show()
plt.plot([1, 2, 3], [4, 5, 6], 'ro-') plt.show()
plt.plot([0, 1, 2], [0, 1, 4], linestyle='--', color='green') plt.show()
This program plots numbers and their squares with blue circles connected by lines. It adds labels and a grid for clarity.
import matplotlib.pyplot as plt x = [0, 1, 2, 3, 4] y = [0, 1, 4, 9, 16] plt.plot(x, y, 'b-o') # blue line with circle markers plt.title('Square Numbers') plt.xlabel('Number') plt.ylabel('Square') plt.grid(True) plt.show()
Always call plt.show() to display the plot.
You can customize colors and line styles using format strings or keyword arguments.
If x is not given, plt.plot uses the index of y values automatically.
plt.plot draws lines connecting points.
You provide x and y data to plot.
Use plt.show() to see the graph.
plt.plot(x, y) function do in matplotlib?plt.plot(x, y) function connects points defined by x and y coordinates with lines.plt.plot.plt.plot(x, y) is correct.import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5, 6] plt.plot(x, y) plt.show()
plt.show() command displays the line graph on screen.import matplotlib.pyplot as plt x = [1, 2, 3] y = [4, 5] plt.plot(x, y) plt.show()
plt.plot([0,1,2,3], [0,1,2,3]) to plot y = x.plt.plot([0,1,2,3], [0,1,4,9]) to plot y = x² on same figure before plt.show().Pass the test and this pattern moves unknown